Run process under current user

前端 未结 3 961
生来不讨喜
生来不讨喜 2021-01-12 03:54

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

System.Diagnostics.Process process = new System.Diagnostics.Process();
//fill         


        
相关标签:
3条回答
  • 2021-01-12 04:18

    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.

    0 讨论(0)
  • 2021-01-12 04:25

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

    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.UserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
    Process.Start(startInfo);
    
    0 讨论(0)
  • 2021-01-12 04:35

    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");

    0 讨论(0)
提交回复
热议问题