I'm looking for a way to figure out the command-line arguments of any Windows service.
For a non-service process, the command-line arguments can be found in the Windows Task Manager, or programmatically by using WMI as shown in this post.
Unfortunately, these two solutions don't work for a Windows service that is started by the ServiceController.Start(String[] args) method. Both of them show only the executable file path on the command-line, even though some arguments were passed in.
I also tried creating a simple service that just logs any command-line arguments it has to the event log. I started it using "sc.exe start <my service> <arg1>"
and verified that <arg1>
was written to the event log.
However, none of the solutions has worked for me. I still only saw the path to the executable file. My OS version is Windows Server 2008 R2 SP1 x64 Enterprise.
Command-line arguments – Task ManagerOpen Task Manager. Right-click the header of any one of the columns and select 'Command line' from the menu. This will add a new 'Command line' column. Look for your app in the Processes list, and check what the Command Line column displays for it.
The simplest command for listing Windows services on PowerShell is Get-Service. It shows all services on your computer, along with their status and names.
Answers. You can add command line arguments to the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\[YourService]\ImagePath registry entry. These will get picked up by the Main() method in your service application. From there you can parse them and pass them to your service via properties, custom constructors, etc.
Click the Start button in the Windows taskbar. In the menu, right-click Command Prompt. On the pop-up right click context menu, select Run as administrator. At the command prompt, enter the SC Config command with the service name to be modified and the parameters to be changed.
There are two types of arguments for services:
SC START \[arguments\]
. This has nothing to do with "command line process arguments".The second type of parameters is probably only known by the service itself, if the implementation makes any use of it which is not the case for many services. I don't think Windows keep track of this when we look at low level Windows structures like the PEB: Process and Thread Structures (MSDN), even the undocumented parts of it, Undocumented functions of NTDLL.
You can find the service EXE file details and edit or just see the commandline options in the registry entry for the service. You'll find that under
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services
Be sure to restart the Services window if you decide to change this as it won't reread it live.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With