Executing a process from .NET application without UAC prompt

大兔子大兔子 提交于 2020-01-21 04:35:11

问题


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;
            }

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

    <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)?


回答1:


To prevent a UAC prompt when launching a second EXE:

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

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

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.

Keywords in specific StringTable entries linked in the executable.

Key attributes in the RC data linked in the executable.

Targeted sequences of bytes within the executable.



来源:https://stackoverflow.com/questions/6164782/executing-a-process-from-net-application-without-uac-prompt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!