我们开发了一个 ActiveX 表单控件,可以安装在 IE8+ 中。 此控件检查注册表项,然后在需要时下载并安装一个小安装程序。 对于管理员,一切都按预期在 Windows 7 和 8 上与任何 IE 版本 8+ 一起工作。
对于非管理员用户,控件运行(它必须由管理员安装,但没关系),它会在路径 C:\users\user\AppData\中下载可执行文件 client_setup.exe
Local\Temp\Low\但当它尝试运行可执行文件时(shellexec 或 createprocess 产生相同的结果)需要管理帐户并出现 UAC 提升提示。
如果非管理员用户下载并安装相同的设置,则不需要管理权限(我们在 exe list 中声明了这一点)。此设置完全安装在用户配置文件和 HKCU 注册表中。
我了解 ActiveX 控件以低权限运行,例如 IE 进程。但是为什么在这种情况下需要提升呢?我们的设置不需要特权。
我尝试在此处的低权限提升策略异常(exception)中添加 ActiveX 控件
HKEY_LOCAL_MACHINE\SOFTWARE\\Microsoft\Internet Explorer\Low Rights\ElevationPolicy
但还是出现UAC提示。
我想允许所有用户运行此设置。我们可以以管理员身份运行一次脚本来授予整个系统的权限。有人可以帮助完成这项任务吗?
测试 1
作为非管理员用户,我尝试手动安装 ActiveX 下载的 .exe,但出现系统错误,无法写入临时目录。如果我使用 Internet Explorer 下载相同的 exe 文件,我可以毫无问题地安装它。
我用 ICACLS 检查过,在 ActiveX 控件下载的 exe 上有一个 Mandatory Label\Low Mandatory Level:(I)(NW)
测试 2
网站已按照 Taxilian 的建议添加到受信任的站点。作为非管理员用户,ActiveX 现在将 .exe 设置保存到 C:\users\user\AppData\Local\Temp (no Low),.exe 不再有低级别标签。但是,CreateProcess 仍然会引发 UAC 提示并失败。
这是我的 CreateProcess 代码。这是 Delphi 代码,但它应该是可读的。
function RunProcess(FileName: string; ShowCmd: DWORD; wait: Boolean; ProcID: PDWORD): Longword;
var
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
FillChar(StartupInfo, SizeOf(StartupInfo), #0);
StartupInfo.cb := SizeOf(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
StartupInfo.wShowWindow := ShowCmd;
if not CreateProcess(nil,
@Filename[1],
nil,
nil,
False,
CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,
nil,
nil,
StartupInfo,
ProcessInfo)
then
Result := WAIT_FAILED
else
begin
if wait = FALSE then
begin
if ProcID <> nil then
ProcID^ := ProcessInfo.dwProcessId;
result := WAIT_FAILED;
exit;
end;
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
end;
if ProcessInfo.hProcess <> 0 then
CloseHandle(ProcessInfo.hProcess);
if ProcessInfo.hThread <> 0 then
CloseHandle(ProcessInfo.hThread);
end;
这是 .exe list 。这是一个简单的设置,将一些文件复制到用户配置文件并在 HKCU 中添加注册表项。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity name="JR.Inno.Setup" processorArchitecture="x86" version="1.0.0.0" type="win32" />
<description>Inno Setup</description>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*" />
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
</application>
</compatibility>
</assembly>
最佳答案
Windows UAC 使用一些启发式方法来检测安装程序。
来自 http://blogs.msdn.com/b/uac/archive/2006/01/13/512776.aspx :
The O/S makes a decision that the application looks like an installer or updater and will automatically invoke elevation to run the program with administrative permissions/privileges when a user runs it. This decision is based on a heuristic. Here are some of the heuristic detection points, although this list is not exhaustive:
- File name detection – looks for the words “setup”, “update”, “install” in the filename
我们的安装程序名称是 client_setup.exe
,因此即使不需要 UAC 也会触发 UAC,请求管理权限,完全忽略 exe list 。我们称其为功能。
将 client_setup.exe
重命名为 client.exe
就足够了,然后运行它。没有出现 UAC 提示,设置成功完成。
这看起来像是 Microsoft 最近的更改。就在 4 个月前,我们的设置启动时没有出现错误。
关于windows - ActiveX 无法在没有特权提升的情况下运行 .exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22195140/