❔ Gleaning process launch information from Process reference attained via GetProcessById?
Given a process ID I would like to determine all parameters necessary to relaunch that process (same parameters, environment, etc.). How could this be done?
I am currently monitoring the process via Process.GetProcessById and waiting for its exit, after which I do some processing. At the end of that processing I would like to relaunch the previously monitored process.
18 Replies
Look at
Process.StartInfo
- it contains the launch argsmhhhhh no
so the things I can think of would be the command line args / environment variables / elevation / working directory? I'm sure I'm missing something
Yea that should pretty much cover it.
I'm assuming it'll have to be some roundabout way given that
StartInfo
isn't just populated - I am just not sure which direction. I can attain the information with OS-specific external calls as well, but would definitely prefer a path through existing framework API.I see someone using WMI to get the command line parameters
WMI?
Stack Overflow
How to get Command Line info for a process in PowerShell or C#
e.g: if I run notepad.exe c:\autoexec.bat,
How can I get c:\autoexec.bat in Get-Process notepad in PowerShell?
Or how can I get c:\autoexec.bat in Process.GetProcessesByName("notepad"); in C#?
something like this
C# has things to run powershell code
and also things to retrieve the WMI stuffs
Ah yes - that was the kind of OS-specific out-of-API workaround I had in mind.
https://superuser.com/a/1675035 also apparently it's not possible to get environment variables of other processes, at least easily
Super User
get a process's private environment variables in Windows using powe...
I have a process (testxx) running on my Database. Every time a user connects with the database the process will start separate session for. All processes include a private environment variable(Clie...
I guess security and stuffs
Makes sense. I guess I could do a less-general-purpose relaunch by hardcoding those and just grabbing the parameters.
But it doesn't look like there's an in-API way of getting those?
There's a component that used to be included in .NET Framework under
System.Management
, now it is available as a NuGet Package instead
there should be examples of how to make a WMI query using itThanks 🙂 That does look super interesting. Windows isn't really a priority as a platform, so I'll leave this as a note for later and conclude that a default API approach isn't available. Thank you walking through this with me 🙂
Something like that
Very nice! Thanks 🙂
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.