从以管理员身份运行的进程中以用户身份启动进程

从以管理员身份运行的进程中以用户身份启动进程

本文介绍了从以管理员身份运行的进程中以用户身份启动进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从另一个以管理员身份运行的程序中启动另一个以用户身份运行的程序。

I want to start another program which runs as user from a program running as administrator.

问题是第二个程序需要使用Outlook,如果该程序以admin身份运行则不可能。主程序需要以管理员身份运行。

The problem is that the second program needs to use outlook, which is not possible if the program runs as admin. The main program needs to run as admin.

我确实想出了这两种解决方案:

I did already come up with this two solutions:

Process.Start("cmd.exe", @"/C runas.exe /savecred /user:" + Environment.UserDomainName + "\\" + Environment.UserName + " " + "\"SomeProgram.exe" + "\"");

Process.Start("explorer.exe", "SomeProgram.exe");

但是我对这两种解决方案都有问题。
第一个询问用户密码(仅在Windows重新启动后的第一次)。
第二个probalby将来将无法工作,因为据我发现,它被认为是一个错误,并且可能会在以后的更新中修复。

But i have a problem with both solutions.The first one asks the user for the password (only the first time after windows was restarted).The second one probalby won`t work in the future, because as far as i found out it is considered as a bug and probably fixed with an future update.

所以我想知道还有没有其他解决方案,用户不需要输入密码?

So I would like to know is there any other solution, where the user does not need to enter his password?

这似乎对我有用:

Process.Start("cmd.exe", @"/C runas.exe /TrustLevel:0x20000  " + "\"SomeProgram.exe" + "\"");


推荐答案

处理类具有 StartInfo 属性,该属性是 ProcessStartInfo 类的实例。此类公开了 UserName Domain Password 成员以指定

Process class has StartInfo property that is an instance of ProcessStartInfo class. This class exposes UserName, Domain and Password members to specify the user you want to run the process.

Process myProcess = new Process();
myProcess.StartInfo.FileName = fileName;
myProcess.StartInfo.UserName = userName;
myProcess.StartInfo.Domain = domain;
myProcess.StartInfo.Password = password;
myProcess.Start();

这篇关于从以管理员身份运行的进程中以用户身份启动进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 19:26