我怎么能脚本一个蝙蝠或cmd停止和启动一个服务可靠的错误检查(或让我知道它不成功的原因)?


当前回答

SC可以用服务做任何事情……启动,停止,检查,配置,和更多…

其他回答

这也可以代替检查代码

net start "Apache tomcat" || goto ExitError

:End  
exit 0  

:ExitError  
echo An error has occurred while starting the tomcat services  
exit 1  

或者您可以使用以下CMD启动远程服务:sc \\<computer> start <service>

下面是Windows 10使用批量启动系统还原的命令:

sc config swprv start= Auto

你可能也会喜欢这些命令:

更改注册表值为自动启动系统恢复 REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" /v DisableSR /t REG_DWORD /d 0 /f 创建系统还原点 Wmic.exe /Namespace:\root\default Path SystemRestore Call CreateRestorePoint "djibe saved your PC", 100,12 修改“系统恢复”磁盘使用率 vssadmin调整shadowstorage /for=C: /on=C: /maxsize=10%

享受

有时你会发现停不动。

我的SQlServer有时会这样做。使用下面的命令行杀死它。如果你真的真的需要你的剧本来消灭那些不停的东西。作为最后的手段,我会让它这么做

taskkill /pid [pid number] /f

I have created my personal batch file for this, mine is a little different but feel free to modify as you see fit. I created this a little while ago because I was bored and wanted to make a simple way for people to be able to input ending, starting, stopping, or setting to auto. This BAT file simply requests that you input the service name and it will do the rest for you. I didn't realize that he was looking for something that stated any error, I must have misread that part. Though typically this can be done by inputting >> output.txt on the end of the line.

%var%只是让用户能够将自己的服务输入其中的一种方式,而不是每次想要启动/停止不同的服务时都必须修改bat文件。

如果我错了,任何人都可以随意纠正我。

@echo off
set /p c= Would you like to start a service [Y/N]?
  if /I "%c%" EQU "Y" goto :1
  if /I "%c%" EQU "N" goto :2
    :1  
    set /p var= Service name: 
:2 
set /p c= Would you like to stop a service [Y/N]?
  if /I "%c%" EQU "Y" goto :3
  if /I "%c%" EQU "N" goto :4
    :3  
    set /p var1= Service name:
:4
set /p c= Would you like to disable a service [Y/N]?
  if /I "%c%" EQU "Y" goto :5
  if /I "%c%" EQU "N" goto :6
    :5  
    set /p var2= Service name:
:6 
set /p c= Would you like to set a service to auto [Y/N]?
  if /I "%c%" EQU "Y" goto :7
  if /I "%c%" EQU "N" goto :10
    :7  
    set /p var3= Service name:
:10
sc start %var%
sc stop %var1%
sc config %var2% start=disabled
sc config %var3% start=auto