简体   繁体   English

Windows Embedded POSReady 2009上的C#Process.Start()管理员特权

[英]C# Process.Start() administrator privileges on Windows Embedded POSReady 2009

I am attempting to call a batch file with administrator privileges in some C# code using System.Diagnostic 's Process.Start() as mentioned here: How to start a Process as administrator mode in C# . 我试图使用System.DiagnosticProcess.Start()在某些C#代码中以管理员权限调用批处理文件,如此处所述: 如何在C#中以管理员身份启动Process

I call the built executable from an elevated command prompt as well as with runas /user:administrator program.exe . 我从提升的命令提示符以及runas /user:administrator program.exe调用生成的可执行文件。 The subprocess succeeds when called outside of my program, but fails at its administrator tasks when called by my program. 在程序外部调用时,子进程成功,但是在程序调用时,其子管理员任务失败。

I have attempted using a manifest and setting the Process.Verb = "runas" , but no luck there. 我尝试使用清单并设置Process.Verb = "runas" ,但那里没有运气。

The subprocess installs a driver and my program verifies the version number if that's relevant. 子进程将安装驱动程序,如果相关,我的程序将验证版本号。

Thank you for the help! 感谢您的帮助!

Make sure you have the following lines in your application's manifest: 确保您的应用程序清单中包含以下几行:

  <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
    <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
  </requestedPrivileges>

Your application will spawn other processes at the same elevation level as itself. 您的应用程序将以与其自身相同的海拔高度生成其他进程。 Meaning that if your application runs as a non-administrator, every process it spawns will run without administrative permissions, too. 这意味着,如果您的应用程序以非管理员身份运行,则它产生的每个进程也将在没有管理权限的情况下运行。

Make sure your parent application has elevated permissions before you start your batch file. 在启动批处理文件之前,请确保您的父应用程序具有提升的权限。

Turns out administrator privileges are only given to executables when using runas , so you can't call the batch file directly. 事实证明,管理员特权仅在使用runas时才赋予可执行文件,因此您不能直接调用批处理文件。 Instead of p.StartInfo.FileName = program.bat , you should call it with p.StartInfo.FileName = "cmd.exe" and p.StartInfo.Arguments = " /C ..." . 而不是p.StartInfo.FileName = program.bat ,应使用p.StartInfo.FileName = "cmd.exe"p.StartInfo.Arguments = " /C ..."来调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM