请查看WiX和DTF:使用启动程序在Vista中强制提升权限运行整个msi文件。
您可以通过GenerateBootstrapper任务在.wixproj文件中自动化此操作。总之:
建立机构。 表明这一点:
<?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="Setup" type="win32" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
并按照以下方式修改您的.wixproj文件:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- standard PropertyGroups and ItemGroups -->
<PropertyGroup>
<WindowsSDK>$(registry:HKEY_LOCAL_MACHINESOFTWAREMicrosoftMicrosoft SDKsWindows@CurrentInstallFolder)</WindowsSDK>
</PropertyGroup>
<PropertyGroup Condition="$(WindowsSDK) == ">
<WindowsSDK>$(registry:HKEY_CURRENT_USERSOFTWAREMicrosoftMicrosoft SDKsWindows@CurrentInstallFolder)</WindowsSDK>
</PropertyGroup>
<PropertyGroup>
<mt_exe>$(WindowsSDK)binmt.exe</mt_exe>
</PropertyGroup>
<ItemGroup>
<BootstrapperFile Include="Microsoft.Windows.Installer.3.1" >
<ProductName>Windows Installer 3.1</ProductName>
</BootstrapperFile>
<!-- more BootstrapperFile items -->
</ItemGroup>
<Target Name="Bootstrapper"
Inputs="$(OutDir)$(TargetFileName)"
Outputs="$(OutDir)Setup.exe"
Condition=" $(OutputType) == package " >
<GenerateBootstrapper ApplicationName="application name"
ApplicationFile="$(TargetFileName)"
BootstrapperItems="@(BootstrapperFile)"
ComponentsLocation="Relative"
OutputPath="$(OutputPath)"
Culture="en-US"
Path="$(WindowsSDK)Bootstrapper" />
</Target>
<Target Name="PatchSetupExe" DependsOnTargets="Bootstrapper">
<Exec Command= "$(mt_exe)" -manifest setup.manifest -outputresource:$(OutDir)Setup.exe;#1 IgnoreExitCode= false />
</Target>
<Import Project="$(MSBuildExtensionsPath)MicrosoftWiXv3.0Wix.targets" />
<PropertyGroup>
<BuildDependsOn>$(BuildDependsOn);Bootstrapper;PatchSetupExe</BuildDependsOn>
</PropertyGroup>
</Project>
现在每次构建将生成一个正确的Setup.exe,可以以提升的身份运行。