在没有UAC提示的情况下从.NET应用程序执行进程 [英] Executing a process from .NET application without UAC prompt

查看:70
本文介绍了在没有UAC提示的情况下从.NET应用程序执行进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我需要从.NET应用程序中启动EXE,但无法绕开弹出的UAC提示。即使在启动另一个EXE之前,也会触发该提示-可能是在调用 Process.Start 之前。

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. The prompt is triggered even before the other EXE is launched - probably on the very call to 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;
            }

两个EXE(我的应用和另一个EXE)都在其清单中定义了此:

Both EXEs (my app and the other EXE) have this defined in their manifest:

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

如何在不触发UAC提示的情况下执行另一个EXE,并使其具有相同的访问令牌作为调用应用程序(以便它可以更改app文件夹中的文件等)?

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:

1)不要使用 Verb = runas -这将为您提供UAC每次

1) do not use Verb = "runas" -- that will give you UAC every time

2)不要为您的EXE使用类似安装程序的文件名。这是来自 MSDN 的规则:

2) do not use setup-like filenames for your EXE. Here is the rule from MSDN:


在创建32位进程之前,检查
以下属性
以确定它是否为
安装程序:

Before a 32 bit process is created, the following attributes are checked to determine whether it is an installer:

文件名包含
之类的关键字,例如安装,设置,更新等。

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.

可执行文件中链接的特定StringTable
条目中的关键字。

Keywords in specific StringTable entries linked in the executable.

RC数据中链接的
中的键属性

Key attributes in the RC data linked in the executable.


可执行文件中的目标字节序列。

Targeted sequences of bytes within the executable.

这篇关于在没有UAC提示的情况下从.NET应用程序执行进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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