2

I am working on renewing an application. The old code had a main method which went through the running processes on windows and checked to see if a certain required process which is a part of the application is running, and if not it starts it. This is how it looks:

Process[] localProcesses = Process.GetProcesses(Environment.MachineName);
bool isHostAlive = false;
 foreach (Process localProc in localProcesses)
 {
   if (localProc.ProcessName == "processIneed")
  {
      isHostAlive = true;
  }
 }
  if (!isHostAlive)
 {
   try
  {
      Process.Start(Application.StartupPath + @"\bin\processIneed.exe");
  }
....

Now what I did was adding an installer class in which I override the Commit method and there I'm activating the process so it will automatically run after installing the application. It looks like this:

string path = Context.Parameters["targetdir"].Replace(@"\\", @"\");
path += @"bin\processIneed.exe";
Process.Start(path);

The problem is that in the old way without activating the process during installation everything worked fine. When I'm starting the process in the new way I've implemented, I see that the path is being built correctly and the process do run in the backgroung but the application just doesn't work as it should.. It kinda "half" works.. I'm not getting any errors or exceptions but it just doesn't work.

The only difference I did notice is that with the old code the process was started under the user name which logged in to windows (user name and password entered in the login screen), while in the new code, the process starts under the user SYSTEM.

Is there a way to start the process from the installer class with the correct credentials? I want to clarify that I don't want to somehow request the password from the user and I don't want to save it or something.. just start with the currently logged on credentials and not with the SYSTEM user.

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203

0 Answers0