如何使用命令行更改 Windows 服务的启动类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6817095/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:34:22  来源:igfitidea点击:

How to change start up type of a windows service using command line

windowsapachecommand-lineservicecommand-line-interface

提问by Mamadex

My focus is on web server.

我的重点是网络服务器。

Apache web server does install service in automatic type (httpd -k install) and Apache does not provide a parameter to install service in manual type (like MySQL: mysqld --install-manual).

Apache Web 服务器确实以自动类型 ( httpd -k install)安装服务,而 Apache 不提供手动类型(如 MySQL: mysqld --install-manual)安装服务的参数。

I read some about SC(C:\Windows\System32\sc.exe) and tried to change it with SC but I couldn't. So what's the solution?

我读了一些关于SC( C:\Windows\System32\sc.exe) 并尝试用 SC 更改它,但我不能。那么有什么解决办法呢?

回答by Dave

SC should be able to handle this, are you getting any errors?

SC应该能够处理这个,你有任何错误吗?

This would set the startup type to manual for a service called 'apache' :

这会将名为“apache”的服务的启动类型设置为手动:

  SC \computername CONFIG apache start= demand

回答by Rhak Kahr

I just apply the same purpose --CHANGE WIN SERVICE STARTUP METHOD-- on a remote machine..

我只是在远程机器上应用相同的目的——改变赢服务启动方法。

C:\MrCMD> REG QUERY \RemoteHostName\HKLM\SYSTEM\CurrentControlSet\Services\WUAUServ

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WUAUServ
    Type    REG_DWORD    0x20
    Start    REG_DWORD    0x2
    ErrorControl    REG_DWORD    0x1
    ImagePath    REG_EXPAND_SZ    %systemroot%\system32\svchost.exe -k netsvcs
    DisplayName    REG_SZ    Automatic Updates
    ObjectName    REG_SZ    LocalSystem
    Description    REG_SZ    Enables the download and installation of Windows updates. If this service is disabled, this computer will not be able to use the Automatic Updates feature or the Windows Update Web site.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WUAUServ\Parameters
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WUAUServ\Security
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WUAUServ\Enum

┌─────────────────────────────────────┐
│ Executed Mon 01/14/2013 14:27:15.31 │ As [MrCMD]
└─────────────────────────────────────┘

C:\MrCMD> REG ADD \RemoteHostName\HKLM\SYSTEM\CurrentControlSet\Services\wuauserv /V Start /T REG_DWORD /d 0x3
Value Start exists, overwrite(Yes/No)? y
The operation completed successfully.

┌─────────────────────────────────────┐
│ Executed Mon 01/14/2013 14:29:57.72 │ As [MrCMD]
└─────────────────────────────────────┘

C:\MrCMD> REG QUERY \RemoteHostName\HKLM\SYSTEM\CurrentControlSet\Services\WUAUServ

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WUAUServ
    Type    REG_DWORD    0x20
    Start    REG_DWORD    0x3
    ErrorControl    REG_DWORD    0x1
    ImagePath    REG_EXPAND_SZ    %systemroot%\system32\svchost.exe -k netsvcs
    DisplayName    REG_SZ    Automatic Updates
    ObjectName    REG_SZ    LocalSystem
    Description    REG_SZ    Enables the download and installation of Windows updates. If this service is disabled, this computer will not be able to use the Automatic Updates feature or the Windows Update Web site.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WUAUServ\Parameters
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WUAUServ\Security
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WUAUServ\Enum

┌─────────────────────────────────────┐
│ Executed Mon 01/14/2013 14:30:37.80 │ As [MrCMD]
└─────────────────────────────────────┘

That's all folks.. :)

这就是所有人.. :)