c – 帮助理解为什么在Win7上为我们的应用程序弹出UAC对话框

前端之家收集整理的这篇文章主要介绍了c – 帮助理解为什么在Win7上为我们的应用程序弹出UAC对话框前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们有一个C非托管应用程序,似乎会导致UAC提示.它似乎发生在Win7而不是Vista上

不幸的是,UAC dlg是系统模态的,所以我不能附加调试器来检查它所在的代码,并且在msdev下运行(我们使用的是2008)在提升模式下运行.

我们在程序/ winmain的开头放了一个消息框,但它甚至没有那么远,所以显然这是在启动代码中.

什么可以如此早地导致UAC通知,以及我可以采取哪些其他措施来追查原因?

编辑

显然,清单在这里是一个重要的问题,但似乎没有帮助我 – 或者我可能没有正确配置清单文件.

有人可以提供样品清单吗?

此外,链接器/ UAC魔术是否会发现程序“可能”写入注册表并基于此设置其UAC要求?有些代码路径可能触发UAC,但是当UAC dlg出现时我们甚至都没有.

另一个奇怪的是,在启用UAC的Vista上似乎没有发生这种情况.

这是一个清单(我认为/是自动生成的):

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*' />
    </dependentAssembly>
  </dependency>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*' />
    </dependentAssembly>
  </dependency>
</assembly>

然后将这个添加到清单列表中以查看它是否有用

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity 
    version="1.0.0.0" 
    processorArchitecture="x86" 
    name="[removed for anonymity]" 
    type="win32" 
/> 
<description>
    [removed for anonymity]
</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.v2">
    <security>
      <requestedPrivileges>        
        <requestedExecutionLevel
          level="asInvoker"
          uiAccess="false"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>

以下是使用ManifestViewer工具的实际EXE

- <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity version="1.0.0.0" processorArchitecture="x86" name="[removed]" type="win32" /> 
  <description>[removed]</description> 
- <dependency>
- <dependentAssembly>
  <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*" /> 
  </dependentAssembly>
  </dependency>
- <dependency>
- <dependentAssembly>
  <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*" /> 
  </dependentAssembly>
  </dependency>
- <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
- <security>
- <requestedPrivileges>
  <requestedExecutionLevel level="asInvoker" uiAccess="false" /> 
  </requestedPrivileges>
  </security>
  </trustInfo>
  </assembly>

它似乎可能是由于我们的应用程序上的XP兼容性设置.我得测试一下. (我们在安装程序中设置了我发现,因为某些声音驱动程序在win7上无法正常工作)

解决方法

Windows根据各种标准自动提升应用程序(在 Understanding and Configuring User Account Control in Windows Vista中列出):

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.

所有这些的最佳解决方案是create a manifest that prevents elevation,尽管重命名文件可能就足够了.

猜你在找的C&C++相关文章