开发者

how to start a process as user then elevate in c# ASP.NET

I am working on a web application that install software on a server.

I can run the install by hand if I lo开发者_Python百科g in a user that is apart of a specific group then run install msi as administrator.

This specific group is apart of the local administrators group.

My app pool is running as Network_Service.

Do I impersonate then use the runAs verb? but then I need to know the u/p as user and u/p of Administrator .. I think

I am using the System.Diagnostics.Process classes.

       System.Diagnostics.ProcessStartInfo oInfo = new System.Diagnostics.ProcessStartInfo(str);
        oInfo.UseShellExecute = false;
        oInfo.ErrorDialog = false;
        oInfo.CreateNoWindow = false;
        oInfo.RedirectStandardOutput = true;


        Process p = System.Diagnostics.Process.Start(oInfo);

        System.IO.StreamReader oReader2 = p.StandardOutput;
        string sRes = oReader2.ReadToEnd();
        oReader2.Close();
    return sRes;


You need to set the UserName and Password properties to the login credentials of an Administrator account.


You can't change the user context of a running process later on. I suggest u use windows authentication and impersonation to be sure the web request is executed as the authenticated user and besides that you don't have to care about the user credentials.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜