C# 进程 - 禁用用户帐户控制提示? [英] C# Process - Disable User Account Control prompt?

查看:78
本文介绍了C# 进程 - 禁用用户帐户控制提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题背景:

我正在调用批处理文件以通过使用 Process 对象针对 MSTest.exe 运行指定的 dll.

I am calling a batch file to run a specified dll against the MSTest.exe through the use of a Process object.

代码:

我想确保此过程始终以提升的管理员权限运行.

I want to ensure that at all times this process is run with elevated administrator permissions.

我目前通过将进程 verb 属性设置为 runas 来执行此操作,如下所示:

I do this currently by setting the process verb property to runas, as shown:

 try
 {
     _process.StartInfo.Verb = "runas";
     _process.StartInfo.CreateNoWindow = true;
     _process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
     _process.StartInfo.Arguments = testLocation + " " + testDll;
     _process.StartInfo.FileName = batchFileLocation;
     _process.Start();
     _process.WaitForExit();
 }
 catch (Exception ex)
 {
     throw ex;
 }

问题:

这按预期运行,但用户帐户控制 (UAC) 提示要求确认我希望该进程运行 .exe.

This runs as expected but the User Account Control (UAC) prompt asks to confirm that I wish the process to run the .exe.

由于此代码是自动化流程的一部分,我不能有任何人工输入来单击提示上的是"按钮,我该如何禁用 UAC 提示?

As this code is part of an an automated process I cannot have any human input to click the 'Yes' button on the prompt, how can I disable the UAC prompt?

推荐答案

您无法绕过 UAC 提示.

You cannot bypass the UAC prompt.

问问自己:如果您在 Windows XP 上执行此操作,您会怎么做?

Ask yourself: What would you do if you were doing this on Windows XP?

假设您在没有 UAC 的操作系统上运行.那你的dll会做什么?您不再享有 UAC 的便利,而是始终以标准用户身份运行.那么你的测试制度会做什么?

Imagine you were running on a operating system that did not have UAC. What would your dll do then? You no longer have the convenience of UAC, and instead you are always running as a standard user. What would your test regime do then?

  • 崩溃?
  • 未通过测试?

如果您不喜欢 UAC 对话框,可以将其关闭.但是您的处境也不会好过,因为现在您就像在 Windows XP 上一样:标准用户并且没有简单的方法可以摆脱它.

If you don't like the UAC dialog you can turn it off. But you'll be in a no better situation, because now you're just like you were on Windows XP: a standard user and no easy way to get out of it.

真正的解决方案是修复您的 dll 正在执行的受保护的操作.例如,如果这是一个COM dll,并且由于您尝试写入HKLM而导致自注册失败,那么您需要

The real solution is to fix what your dll is doing that is protected. For example, if this is a COM dll, and the self-registration is failing because you are trying to write to HKLM, then you need to

  • 授予您对 HKLM\Software\Classes 节点的完全控制权

如果您的 dll 因为您尝试写入 C:\Program Files 而崩溃,那么您需要将 C:\Program Files 上的安全设置更改为给自己访问权限.

If your dll is crashing because you are trying to write to C:\Program Files, then you need to change the security settings on C:\Program Files to give yourself access.

解决方案是修复失败的地方.

The solution is to fix what is failing.

这篇关于C# 进程 - 禁用用户帐户控制提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆