Run process under current user

There is "Setup project" in VS. During installation I launch another process:

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

If I run installer under Windows 7 and install for "Everyone", process start under the SYSTEM. If I install "Just for me", process start under Current user. How do I always start process under Current user?


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

To launch the process call ProcessAsUser.Launch("program name");


I had a similar problem: My setup extension (custom action) needed Admin privileges which brought up an elevation box. After I start my application at the end of "Just for Me" the process had settings that were made for the admin context. For example my user account likes to see all extensions of files in Windows Explorer but the admin account was configured to hide them. So in every file open box I couldn't see the extensions. To cure this this piece of code worked:

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

It works only in "Just for Me" mode, in "Everyone" the admin's settings are used. But this is ok for me.


使用ProcessStartInfo类及其属性UserName ,然后将其用作Process.Start静态方法的参数。

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.UserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
Process.Start(startInfo);
链接地址: http://www.djcxy.com/p/10490.html

上一篇: 保持RichTextBox中垂直居中的FlowDocument游标

下一篇: 在当前用户下运行进程