albarmat albarmat - 1 year ago 75
PowerShell Question

windows service update exe options without remove / reinstall

I've a windows service installed and working fine with a path to exe :


c:\myproject\mybinary.exe -home d:\home - generateFiles false


I want to add another option :
-option optionValue


Since I have around 200 different services, installed in a 15 different servers, it is complicated to uninstall and reinstall with the new option.

Is there somehow to add the new option without any change to the service binary?

Answer Source

PowerShell:

Get-WmiObject win32_service -filter "Name='My Service'" `
    | Invoke-WmiMethod -Name Change `
    -ArgumentList @($null,$null,$null,$null,$null, `
    "c:\myproject\mybinary.exe -home d:\home -generateFiles false -option optionValue")

Or:

Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\My Service" `
    -Name ImagePath -Value "c:\myproject\mybinary.exe -home d:\home -generateFiles false -option optionValue"

You would need to restart service afterwards: Restart-Service "My Service". See also here.