windows 修改windows服务的“可执行路径”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7190480/
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
Modifying the "Path to executable" of a windows service
提问by GenericJon
I'd like to modify the path to my application, but doing so breaks it because the service still points to the old location.
我想修改我的应用程序的路径,但这样做会破坏它,因为该服务仍指向旧位置。
By going to Administrative Tools > Services
you can open a properties dialog and view the Path to executable
, but there is no way to change it.
通过转到,Administrative Tools > Services
您可以打开一个属性对话框并查看Path to executable
,但无法更改它。
Is there any way a user can modify the service path without having to reinstall the application ?
用户有什么方法可以修改服务路径而无需重新安装应用程序?
采纳答案by Niall Connaughton
There is also this approach seen on SuperUserwhich uses the sc
command line instead of modifying the registry:
在 SuperUser 上也看到了这种方法,它使用sc
命令行而不是修改注册表:
sc config <service name> binPath= <binary path>
Note: the space after binPath=
is important. You can also query the current configuration using:
注意:后面的空格binPath=
很重要。您还可以使用以下方法查询当前配置:
sc qc <service name>
This displays output similar to:
这将显示类似于以下内容的输出:
[SC] QueryServiceConfig SUCCESS
SERVICE_NAME: ServiceName
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 : user-name@domain-name
[SC] QueryServiceConfig 成功
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 : user-name@domain-name
回答by Matt McHugh
It involves editing the registry, but service information can be found in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services
. Find the service you want to redirect, locate the ImagePath
subkey and change that value.
它涉及编辑注册表,但可以在HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services
. 找到要重定向的服务,找到ImagePath
子项并更改该值。
回答by Greg Sansom
You could also do it with PowerShell:
你也可以用 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")
Or:
或者:
Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\My Service" `
-Name ImagePath -Value "C:\Program Files (x86)\My Service\NewName.EXE"
回答by Antony Joseph
Open Run(win+R) , type "Regedit.exe" , to open "Registry Editor", go to
打开 Run(win+R) ,输入“Regedit.exe”,打开“注册表编辑器”,进入
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services
find "Apache2.4" open the folder find the "ImagePath" in the right side, open "ImagePath" under "value Data" put the following path:
找到“ Apache2.4”打开文件夹,在右侧找到“ ImagePath”,打开“ value Data”下的“ImagePath ”放入如下路径:
"C:\xampp\apache\bin\httpd.exe" -k runservicefoe XAMPP for others point to the location where Apache is installed and inside locate the bin folder "C:(Apache installed location)\bin\httpd.exe" -k runservice
"C:\xampp\apache\bin\httpd.exe" -k runservicefoe XAMPP for others 指向安装Apache的位置,在里面找到bin文件夹"C:(Apache安装位置)\bin\httpd.exe" -k 运行服务
回答by Codemaker
You can't directly edit your path to execute of a service. For that you can use sc command,
您不能直接编辑执行服务的路径。为此,您可以使用 sc 命令,
SC CONFIG ServiceName binPath= "Path of your file"
Eg:
例如:
sc config MongoDB binPath="I:\Programming\MongoDB\MongoDB\bin\mongod.exe --config I:\Programming\MongoDB\MongoDB\bin\mongod.cfg --service"
回答by John Duskin
Slight modification to this @CodeMaker 's answer, for anyone like me who is trying to modify a MongoDB service to use authentication.
对这个@CodeMaker 的答案稍作修改,适用于像我这样试图修改 MongoDB 服务以使用身份验证的人。
When I looked at the "Path to executable" in "Services" the executed line already contained speech marks. So I had to make minor modification to his example.
当我查看“服务”中的“可执行文件路径”时,执行的行已经包含语音标记。所以我不得不对他的例子做一些小的修改。
To be specific.
再具体一点。
- Type Services in Windows
- Find MongoDB (or the service you want to change) and open the service, making sure to stop it.
- Make a note of the Service Name (not the display name)
- Look up and copy the "Path to executable" and copy it.
- Windows 中的类型服务
- 找到 MongoDB(或您要更改的服务)并打开该服务,确保将其停止。
- 记下服务名称(不是显示名称)
- 查找并复制“可执行文件的路径”并复制它。
For me the path was (note the speech marks)
对我来说路径是(注意语音标记)
"C:\Program Files\MongoDB\Server.2\bin\mongod.exe" --config "C:\Program Files\MongoDB\Server.2\bin\mongod.cfg" --service
In a command line type
在命令行类型中
sc config MongoDB binPath= "<Modified string with \" to replace ">"
In my case this was
就我而言,这是
sc config MongoDB binPath= "\"C:\Program Files\MongoDB\Server.2\bin\mongod.exe\" --config \"C:\Program Files\MongoDB\Server.2\bin\mongod.cfg\" --service -- auth"
回答by Rhak Kahr
A little bit deeper with 'SC' command, we are able to extract all 'Services Name' and got all 'QueryServiceConfig' :)
使用“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]
Then, continue with 'CMD'..
然后,继续'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]
Raw data is ready for feeding 'future batch file' so the result is look like this below!!!
原始数据已准备好用于“未来批处理文件”,因此结果如下所示!!!
+ -------------+-------------------------+---------------------------+---------------+--------------------------------------------------+------------------+-----+----------------+--------------+--------------------+
| 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 |
But, HTML will be pretty easier :D
但是,HTML 会更容易:D
Any bright ideas for improvement are welcome V^_^
欢迎任何改进的好主意V^_^
回答by Kim Wilson
You can delete the service:
您可以删除该服务:
sc delete ServiceName
Then recreate the service.
然后重新创建服务。