C
C#14mo ago
AngryAnt

❔ 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
phaseshift
phaseshift14mo ago
Look at Process.StartInfo - it contains the launch args
Chiyoko_S
Chiyoko_S14mo ago
Chiyoko_S
Chiyoko_S14mo ago
mhhhhh 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
AngryAnt
AngryAnt14mo ago
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.
Chiyoko_S
Chiyoko_S14mo ago
I see someone using WMI to get the command line parameters
AngryAnt
AngryAnt14mo ago
WMI?
Chiyoko_S
Chiyoko_S14mo ago
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#?
Chiyoko_S
Chiyoko_S14mo ago
something like this C# has things to run powershell code and also things to retrieve the WMI stuffs
AngryAnt
AngryAnt14mo ago
Ah yes - that was the kind of OS-specific out-of-API workaround I had in mind.
Chiyoko_S
Chiyoko_S14mo ago
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...
Chiyoko_S
Chiyoko_S14mo ago
I guess security and stuffs
AngryAnt
AngryAnt14mo ago
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?
Chiyoko_S
Chiyoko_S14mo ago
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 it
AngryAnt
AngryAnt14mo ago
Thanks 🙂 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 🙂
Chiyoko_S
Chiyoko_S14mo ago
Something like that
AngryAnt
AngryAnt14mo ago
Very nice! Thanks 🙂
Accord
Accord14mo ago
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.
Want results from more Discord servers?
Add your server
More Posts