简体   繁体   English

在没有 UAC 提示的情况下从 .NET 应用程序执行进程

[英]Executing a process from .NET application without UAC prompt

I have a scenario where I need to launch an EXE from my .NET application, but I can't get around the UAC prompt that pops up.我有一个场景,我需要从我的 .NET 应用程序启动一个 EXE,但我无法绕过弹出的 UAC 提示。 The prompt is triggered even before the other EXE is launched - probably on the very call to Process.Start .甚至在另一个 EXE 启动之前就会触发提示 - 可能是在调用Process.Start时。

I use this code for launching the app:我使用此代码启动应用程序:

            var info = new ProcessStartInfo(path, "params");
            info.Verb = "runas";
            try
            {
                Process.Start(info);
            }
            catch (System.ComponentModel.Win32Exception)
            {
                // Person denied UAC escallation
                return false;
            }

Both EXEs (my app and the other EXE) have this defined in their manifest:两个 EXE(我的应用程序和另一个 EXE)都在它们的清单中定义了这个:

    <requestedExecutionLevel level="asInvoker" uiAccess="false" />

How can I execute the other EXE without triggering a UAC prompt, and have it have the same access token as the calling application (so it can make changes to files in the app folder etc)?如何在不触发 UAC 提示的情况下执行另一个 EXE,并使其具有与调用应用程序相同的访问令牌(因此它可以更改应用程序文件夹等中的文件)?

To prevent a UAC prompt when launching a second EXE:要在启动第二个 EXE 时阻止 UAC 提示:

1) do not use Verb = "runas" -- that will give you UAC every time 1) 不要使用Verb = "runas" - 每次都会给你 UAC

2) do not use setup-like filenames for your EXE. 2) 不要为您的 EXE 使用类似设置的文件名。 Here is the rule from MSDN :这是来自MSDN的规则:

Before a 32 bit process is created, the following attributes are checked to determine whether it is an installer:在创建 32 位进程之前,会检查以下属性以确定它是否是安装程序:

Filename includes keywords like "install," "setup," "update," etc.文件名包括“安装”、“设置”、“更新”等关键字。

Keywords in the following Versioning Resource fields: Vendor, Company Name, Product Name, File以下版本控制资源字段中的关键字:供应商、公司名称、产品名称、文件

Description, Original Filename, Internal Name, and Export Name.描述、原始文件名、内部名称和导出名称。

Keywords in the side-by-side manifest embedded in the executable.嵌入在可执行文件中的并排清单中的关键字。

Keywords in specific StringTable entries linked in the executable.可执行文件中链接的特定 StringTable 条目中的关键字。

Key attributes in the RC data linked in the executable.可执行文件中链接的 RC 数据中的关键属性。

Targeted sequences of bytes within the executable.可执行文件中的目标字节序列。

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

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