![]() |
1
325
使用
DESCRIPTION: SC is a command line program used for communicating with the NT Service Controller and services. USAGE: sc <server> [command] [service name] ... The option <server> has the form "\\ServerName" Further help on commands can be obtained by typing: "sc [command]" Commands: query-----------Queries the status for a service, or enumerates the status for types of services. queryex---------Queries the extended status for a service, or enumerates the status for types of services. start-----------Starts a service. pause-----------Sends a PAUSE control request to a service. interrogate-----Sends an INTERROGATE control request to a service. continue--------Sends a CONTINUE control request to a service. stop------------Sends a STOP request to a service. config----------Changes the configuration of a service (persistant). description-----Changes the description of a service. failure---------Changes the actions taken by a service upon failure. qc--------------Queries the configuration information for a service. qdescription----Queries the description for a service. qfailure--------Queries the actions taken by a service upon failure. delete----------Deletes a service (from the registry). create----------Creates a service. (adds it to the registry). control---------Sends a control to a service. sdshow----------Displays a service's security descriptor. sdset-----------Sets a service's security descriptor. GetDisplayName--Gets the DisplayName for a service. GetKeyName------Gets the ServiceKeyName for a service. EnumDepend------Enumerates Service Dependencies. The following commands don't require a service name: sc <server> <command> <option> boot------------(ok | bad) Indicates whether the last boot should be saved as the last-known-good boot configuration Lock------------Locks the Service Database QueryLock-------Queries the LockStatus for the SCManager Database EXAMPLE: sc start MyService |
![]() |
2
193
和
告诉你他们是成功了还是失败了。例如
如果从批处理文件运行,则可以访问返回代码的错误级别。0表示成功。任何更高的值都表示失败。
作为BAT文件,
输出如下:
返回码
编辑20.04.2015 返回代码:
|
![]() |
3
27
您可以使用net start命令,然后检查errorlevel环境变量,例如
免责声明:我已经从头开始写了这篇文章,但我认为它会起作用。 |
![]() |
4
8
不检查代码,这也有效
|
![]() |
5
7
我已经为这个创建了我的个人批处理文件,我的有点不同,但是您可以随意修改。 我在不久前就创建了这个,因为我很无聊,想为人们提供一个简单的方法,让他们能够输入结束、开始、停止或设置为自动。这个BAT文件只是请求您输入服务名,它将为您完成其余的工作。我不知道他在找什么错误的东西,我一定是看错了。尽管通常可以通过在行的末尾输入>>output.txt来完成。 %var%只是一种让用户能够将自己的服务输入其中的方法,而不必每次启动/停止不同的服务时都修改BAT文件。 如果我错了,任何人都可以随意纠正我。
|
![]() |
6
6
使用返回代码
|
![]() |
7
5
语法总是让我…所以… 这里明确地介绍了如何在批处理文件中添加一行,该行将杀死远程服务(在另一台计算机上)。如果您是两台计算机上的管理员,请以管理员身份运行.bat,并且这些计算机在同一域中。计算机名遵循UNC格式\myserver
在这种情况下…在服务管理器中查看服务的属性时,p4_1既是服务名,又是显示名。必须使用服务名称。 为你的服务对象…请务必附加原因代码和注释!即“4”,等于“计划”并注释“停止服务器进行维护”
|
![]() |
8
4
我们认为“net stop”会停止服务。可悲的是,现实并不是黑白的。如果服务需要很长时间才能停止,则命令将在服务停止之前返回。但是,除非检查错误级别,否则您不会知道。 解决方案似乎是循环查找服务的状态,直到服务停止为止,每次循环都会暂停。 但是再一次… 我看到第一个服务需要很长时间才能停止,然后后续服务的“net stop”似乎什么也没做。在服务管理器中查看服务,它的状态仍然是“已启动”——没有更改为“正在停止”。然而,我可以使用SCM手动停止第二个服务,它将在3或4秒内停止。 |
![]() |
9
3
或者可以使用以下命令启动远程服务:
|
![]() |
10
2
我刚才使用了jonas的例子,创建了0到24个错误级别的完整列表。其他职位是正确的
但这对我很有用:
变化
|
![]() |
11
2
手动服务重新启动正常-services.msc有“restart”按钮,但在命令行中sc和net命令都缺少“restart”开关,如果在cmd/bat文件中计划重新启动,则服务会立即停止并启动,有时会因为服务尚未停止而出错,需要一些时间来关闭。 这可能会产生一个错误: SC停止 SC启动 插入超时是一个好主意,我使用ping(它每1秒ping一次): SC停止 Ping本地主机-N 60 SC启动 |
![]() |
12
1
|
![]() |
13
1
有时你会发现停站不起作用。 我的SQLServer有时会这样做。使用下面的命令行可以杀死它。如果你真的需要你的脚本来杀死那些无法停止的东西。我会让它做最后的选择
|
![]() |
14
1
以下是使用批处理启动系统还原的Windows 10命令:
您也可能喜欢这些命令:
享受 |
![]() |
15
0
我正在用C语言编写一个Windows服务,stop/uninstall/build/install/start循环太累了。写了一个小剧本,叫它
只需设置这3个变量
注意:这需要从Visual Studio开发人员命令行运行
也许这对某人有帮助:) |
|
Itachi · 无法为python项目安装“DAWG”包 2 年前 |
![]() |
arsaces · 将文本添加到特定文件的末尾 3 年前 |
![]() |
Ali EXE · 如何根据bat中命令的输出设置变量? 3 年前 |
![]() |
viniciussss · 禁用CMD start命令中的弹出消息 7 年前 |
![]() |
Ran · 每当我尝试执行命令行提示符时,Unity就会阻塞 7 年前 |
![]() |
Clint Hartley · 你能把goto和if放在一行吗? 7 年前 |
![]() |
J-Cake · 将CMD参数传递给python 7 年前 |