Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I discover how my process was started

Tags:

c#

.net

We've got a winforms LOB application, which under normal circumstances should be started from a launcher that should do basic version checks and download any updated components, before spawning the main process.

One problem we're seeing is that some members of staff have found it loads faster by not running the update application, however this can lead to people not having the latest features and causes all manner of headache to support.

What I'd like to be able to do is to throw up a warning if they haven't gone in through the initialise application. Ideally, I'd like to be able to do this without having to change the update application (as that means going and installing a new MSI on each client), and the approach that springs out is to find some way of finding information about the process that started "me" and check against a white/black list, forever I can't seem to find a way to do this?


Aside: Of course, if I did resort to changing the update application, I'd probably change it to either pass a pre-shared secret as a command line argument, or better still, change the application such that I could just load it as a class library and instantiate the relevant class via reflection. ClickOnce has been ruled out as it does not support being installed for multiple users

like image 857
Rowland Shaw Avatar asked Jul 14 '09 14:07

Rowland Shaw


People also ask

How do I find process details?

The /proc directory contains details about processes and other system information such as kernel, memory usage, CPU data, and configuration parameters. The operating system mounts /proc at boot. We can read three files to gain the name or the command line of the process: comm, exe, and cmdline.


2 Answers

See here: How to get parent process in .NET in managed way

From the link:

using System.Diagnostics;
PerformanceCounter pc = new PerformanceCounter("Process",
"Creating Process ID", Process.GetCurrentProcess().ProcessName);
return Process.GetProcessById((int)pc.NextValue());

[Edit: Also see the System.Diagnostics FAQ for some more information about this. Thanks to Justin for the link.]

like image 163
Simon P Stevens Avatar answered Sep 27 '22 20:09

Simon P Stevens


I find if your process - which I assume you have control over - checks its version number vs the latest released version number (placed somewhere central db/ftp wherever u look for the update) , then you have all that logic in one place. I think that would be a simpler solution.

like image 34
AndersK Avatar answered Sep 27 '22 21:09

AndersK