Modifying the “Path to executable” of a windows service

后端 未结 8 1503
终归单人心
终归单人心 2020-11-30 17:11

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

相关标签:
8条回答
  • 2020-11-30 17:40

    You could also do it with 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"
    
    0 讨论(0)
  • 2020-11-30 17:43

    There is also this approach seen on SuperUser which uses the sc command line instead of modifying the registry:

    sc config <service name> binPath= <binary path>
    

    Note: the space after binPath= is important. You can also query the current configuration using:

    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
    
    0 讨论(0)
  • 2020-11-30 17:46

    Slight modification to this @CodeMaker 's answer, for anyone like me who is trying to modify a MongoDB service to use authentication.

    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.

    1. Type Services in Windows
    2. Find MongoDB (or the service you want to change) and open the service, making sure to stop it.
    3. Make a note of the Service Name (not the display name)
    4. Look up and copy the "Path to executable" and copy it.

    For me the path was (note the speech marks)

    "C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe" --config "C:\Program Files\MongoDB\Server\4.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\4.2\bin\mongod.exe\" --config \"C:\Program Files\MongoDB\Server\4.2\bin\mongod.cfg\" --service -- auth"
    
    0 讨论(0)
  • 2020-11-30 17:48

    Open Run(win+R) , type "Regedit.exe" , to open "Registry Editor", go to

    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:

    "C:\xampp\apache\bin\httpd.exe" -k runservice foe 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

    0 讨论(0)
  • 2020-11-30 17:51

    You can't directly edit your path to execute of a service. For that you can use sc command,

    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"
    
    0 讨论(0)
  • 2020-11-30 17:57

    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.

    0 讨论(0)
提交回复
热议问题