我想修改我的应用程序的路径,但这样做会破坏它,因为服务仍然指向旧的位置。修改Windows服务的“可执行文件路径”
通过转到Administrative Tools > Services
,您可以打开属性对话框并查看Path to executable
,但无法对其进行更改。
用户可以通过任何方式修改服务路径而无需重新安装应用程序吗?
我想修改我的应用程序的路径,但这样做会破坏它,因为服务仍然指向旧的位置。修改Windows服务的“可执行文件路径”
通过转到Administrative Tools > Services
,您可以打开属性对话框并查看Path to executable
,但无法对其进行更改。
用户可以通过任何方式修改服务路径而无需重新安装应用程序吗?
还有this approach seen on SuperUser它使用sc
命令行,而不是修改注册表的:
sc config <service name> binPath= <binary path>
注:binPath=
后的空间是很重要的。还可以使用查询当前配置:
sc qc <service name>
这将显示类似的输出:
[SC] QueryServiceConfig SUCCESS
SERVICE_NAME:服务名称
TYPE : 10 WIN32_OWN_PROCESS START_TYPE : 2 AUTO_START ERROR_CONTROL : 1 NORMAL BINARY_PATH_NAME : C:\Services\ServiceName LOAD_ORDER_GROUP : TAG : 0 DISPLAY_NAME : <Display name> DEPENDENCIES : SERVICE_START_NAME : [email protected]
它涉及到编辑注册表,但服务信息可以在HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services
找到。找到您想要重定向的服务,找到ImagePath
子项并更改该值。
你也可以使用PowerShell做到这一点:
Get-WmiObject win32_service -filter "Name='My Service'" `
| Invoke-WmiMethod -Name Change `
-ArgumentList @($null,$null,$null,$null,$null, `
"C:\Program Files (x86)\My Service\NewName.EXE")
或者:
Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\My Service" `
-Name ImagePath -Value "C:\Program Files (x86)\My Service\NewName.EXE"
一个稍微深一点与“SC”命令,我们可以提取所有“服务名称”,并获得所有 'QueryServiceConfig' :)
>SC QUERY > "%computername%-services.txt" [enter]
>FIND "SERVICE_NAME: " "%computername%-services.txt" /i > "%computername%-services-name.txt" [enter]
>NOTEPAD2 "%computername%-services-name.txt" [enter]
然后,继续用“CMD” ..
>FOR /F "DELIMS= SKIP=2" %S IN ('TYPE "%computername%-services-name.txt"') DO @SC QC "%S" >> "%computername%-services-list-config.txt" [enter]
>NOTEPAD2 "%computername%-services-list-config.txt" [enter]
原始数据已准备好饲养未来的批处理文件“,因此结果是这个样子低于!
+ -------------+-------------------------+---------------------------+---------------+--------------------------------------------------+------------------+-----+----------------+--------------+--------------------+
| SERVICE_NAME | TYPE | START_TYPE | ERROR_CONTROL | BINARY_PATH_NAME | LOAD_ORDER_GROUP | TAG | DISPLAY_NAME | DEPENDENCIES | SERVICE_START_NAME |
+ -------------+-------------------------+---------------------------+---------------+--------------------------------------------------+------------------+-----+----------------+--------------+--------------------+
+ WSearch | 10 WIN32_OWN_PROCESS | 2 AUTO_START (DELAYED) | 1 NORMAL | C:\Windows\system32\SearchIndexer.exe /Embedding | none | 0 | Windows Search | RPCSS | LocalSystem |
+ wuauserv | 20 WIN32_SHARE_PROCESS | 2 AUTO_START (DELAYED) | 1 NORMAL | C:\Windows\system32\svchost.exe -k netsvcs | none | 0 | Windows Update | rpcss | LocalSystem |
但是,HTML将是相当容易:d
任何改进的高见,欢迎V^_^
或使用'sc'这是更容易,更容易而不喜欢搞砸。 – Liam
我会推荐这种方法通过直接注册表更改。许多路径需要带引号的字符串,您可以输入如下,例如MS SQL Server: 'sc config mssqlserver binPath =“\”F:\ SQL DATA \ MSSQL10.MSSQLSERVER \ MSSQL \ Binn \ sqlservr.exe \“ -sMSSQLSERVER“' –
在直接注册表修改方法中,它在部署脚本中可能也更好一些。 –
甜。清洁,而不是注册登记。 **注意:您需要关闭并打开services.msc才能看到更改。 – yonsk