I have a process Perl.exe which is running a script. I'd like to programatically find the name of the script being executed.
I know it can be done: Mark Rusinovitch in his ProcessExplorer finds that info in command which started a Perl's process. So I thought I'd be able to find it in System.Diagnostics.Process.StartInfo.FileName. Unfortunatelly it seems I am on a wrong track here - the two pieces of data which I am looking i.e .FileName and .Arguments are empty.
I'm fresh out of ideas, can someone suggests any alternatives what sould I try to get the info I'm looking for
Regards, Vladimir
Loading
Sam HobbsPosted Nov 16, 2009, 10:02 PM
The following is equivalent C# code. Be sure to add a reference to System.Management.dll and a using for System.Management.
Note that this forum's software caused me to delete this post accidentally, so I am posting the message a second time.
Sam HobbsPosted Nov 16, 2009, 9:23 PM
This will hopefully get you closer. I don't know how to use WMI in C# but I assume it can be done. The following is a VBScript script, so save the following script in a file with the vbs extension and then execute it using the CScript command. You do not want to execute the file by double-clicking on the file since it will (I think) produce a messagebox for each process, which will be many. The output in a command-line window should show you that the data can be obtained using WMI. So then it is simply a matter of using WMI in your C# program.
Note that the underscore ("_") is VB's way to continue a line, so the "Set objWMIService" line is continued onto two additional lines. I do that to keep the line form being very long, but you can combine the lines into one if you want. You are a multi-lingual guy, right?