Process.Start() 不在同一用户下生成新进程
我总是有这样的印象:当您以 (domain\user) mydomain\myuser
身份运行进程时,使用 Process.Start()
时,它将启动这个新进程使用相同的凭据进行处理 - mydomain\myuser
。
我遇到的问题是我的 Process.Start()
调用似乎在 SYSTEM 帐户下创建一个进程,这导致我在启动的进程中出现权限问题(必须在管理员帐户下运行)由于它所做的工作)。如果它改变了事情 - 我会从Windows安装程序中生成这个进程(自定义构建的exe)。
有什么建议吗?我读过有关 Windows 组策略(可能)对此有影响的内容,但老实说,我对此一无所知。
编辑:一个小片段:
其中 exename
和 commandLine
是此方法主体的参数:
ProcessStartInfo procInfo = new ProcessStartInfo(exeName, commandLine);
procInfo.WorkingDirectory = workingDirectory;
procInfo.UseShellExecute = false;
procInfo.CreateNoWindow = true;
Process process = Process.Start(procInfo);
Process.WaitForExit();
return process.ExitCode;
I was always under the impression that when you're running a process as (domain\user) mydomain\myuser
, when using Process.Start()
it would start this new process using the same credentials - mydomain\myuser
.
The issue I'm having is that my Process.Start()
call seems to be creating a process under the SYSTEM account which is causing me permission issues in the started process (which must run under an admin account due to the work it does). If it changes things - I'm spawning this process (a custom built exe) from within a windows installer.
Any suggestions? I've read about windows group policies (possibly) having an impact on this, but if I'm honest, it's lost on me.
EDIT: a little snippet:
Where exename
and commandLine
are parameters for this method body:
ProcessStartInfo procInfo = new ProcessStartInfo(exeName, commandLine);
procInfo.WorkingDirectory = workingDirectory;
procInfo.UseShellExecute = false;
procInfo.CreateNoWindow = true;
Process process = Process.Start(procInfo);
Process.WaitForExit();
return process.ExitCode;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 procInfo.UseShellExecute 设置为 true,或者将 cmd 作为进程执行,并将 exe 作为 cmd 命令的参数。当 UseShellExecute 设置为 false 时,会出现许多有趣的副作用: UseShell执行
Either set procInfo.UseShellExecute to true, or execute cmd as a process with your exe as a parameter to the cmd command. When UseShellExecute is set to false, here are a lot of interesting side effects: UseShellExecute
你的印象是真的。 Process.Start() 将始终在当前用户的凭据下启动新进程 - 除非您在 ProcessStartInfo 中提供替代凭据或使用采用凭据的重载之一。
一定还有另一个问题 - 分享您的代码片段。
更新
好的!您没有提到任何有关安装程序的内容。所有 MSI 安装程序都将在系统下运行,因为它们将由“Windows Installer”运行,您可以检查它们,并且它们在SYSTEM下运行。
Your impression is true. Process.Start() will always start the new process under current user's credentials - unless you provide alternative credentials in the
ProcessStartInfo
or use one of the overloads that take credentials.There must be another problem - share a snippet of your code.
UPDATE
OK! You did not mention anything about installer. All MSI installers will be running under system since they will be run by "Windows Installer" which you can check and they run under SYSTEM.