Run the process with the current user

There is an “Installation Project” in VS. During installation, I start another process:

System.Diagnostics.Process process = new System.Diagnostics.Process(); //fill StartInfo and run call Start() process.Start(); 

If I run the installer under Windows 7 and installed for "Everyone", start the process on the system. If I install "Just for me", start the process with the current user. How do I always start the process with the current user?

+7
source share
3 answers

I found a very simple solution. All you need is just create a new class and copy the text from this link.

To start a process call ProcessAsUser.Launch("program name");

+4
source

I had a similar problem: for my configuration extension (custom action) I need administrator privileges that raised the elevation frame. After I started the application at the end of “Just for me”, the process had settings that were made for the administrator context. For example, my user account likes to see all file extensions in Windows Explorer, but the administrator account has been configured to hide them. Therefore, in every open file box I could not see the extension. To cure this piece of code, follow these steps:

 ProcessStartInfo startInfo = new ProcessStartInfo(ShortcutTarget); startInfo.LoadUserProfile = true; startInfo.UseShellExecute = false; Process.Start(startInfo); 

It works only in the "Only for me" mode, in "All" the administrator settings are used. But this is normal for me.

0
source

Use the ProcessStartInfo class and its UserName property, then use it as an argument to the Process.Start static method.

 ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.UserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name; Process.Start(startInfo); 
-one
source

All Articles