Wix在安装完成之后,如果遇到非管理员用户(域用户或Win7+系统,UAC权限问题等),修改配置文件(setting.ini)文件时,会遇到文件权限为只读,无法修改问题:
解决方案有两种:
首先添加UtilExtension的dll引用,并在Product.wxs文件头出添加如下代码:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
1、给文件夹添加权限
<ComponentGroup Id="MainComponentsGrp" Directory="INSTALLFOLDER"> <Component Id="CMP_Permission" Guid="{DC0D5A83-06FE-4351-9063-F3596EC644BC}"> <CreateFolder> <util:PermissionEx User="Users" GenericAll="yes"/> </CreateFolder> </Component> <Component Id="CMP_LibraryForSnifferdll" Guid="{2C609842-7F2A-44E5-9A5E-50ED034B1825}"> <File Id="LibraryForSnifferdll" Source="$(var.Sniffer.TargetDir)/LibraryForSniffer.dll" KeyPath="yes"/> </Component> <Component Id="CMP_Settingconfig" Guid="{1997601A-3FEA-400E-9A82-18100723A647}"> <File Id="Settingconfig" Source="$(var.Sniffer.TargetDir)/Setting.config" KeyPath="yes"/> </Component> <Component Id="CMP_SimpleSnifferexe" Guid="{7AD279DE-FD0F-4643-813E-B1C2B5AF3BCC}"> <File Id="SimpleSnifferexe" Source="$(var.Sniffer.TargetDir)/Sniffer.exe" KeyPath="yes"/> </Component> </ComponentGroup>
2、给单独的文件添加权限
<Component Id="CMP_Settingconfig" Directory="INSTALLFOLDER" Guid="{1997601A-3FEA-400E-9A82-18100723A647}"> <File Id="Settingconfig" Source="$(var.Sniffer.TargetDir)/Setting.config" KeyPath="yes"> <util:PermissionEx User="Users" GenericAll="yes"/> </File> </Component>
GenericAll为用于该文件的所有权限。其它权限请参照本文最后的备注。当然,也可以新建(系统)用户,并添加该用户的权限,当然删除软件之后,新添加的用户也会随之删除,如下:
<Component Id="CMP_Settingconfig" Directory="INSTALLFOLDER" Guid="{1997601A-3FEA-400E-9A82-18100723A647}"> <util:User Id="MyNewUser" CreateUser="yes" Name="pencilzhang" Password="123456" PasswordNeverExpires="yes" RemoveOnUninstall="yes" UpdateIfExists="yes" /> <File Id="Settingconfig" Source="$(var.Sniffer.TargetDir)/Setting.config" KeyPath="yes"> <util:PermissionEx User="pencilzhang" GenericAll="yes"/> </File> </Component>
这样,安装完成之后,pencilzhang会出现在操作系统用户列表中,密码为"123456"。
注意事项:如果是中文环境下,需要添加UtilExtension的本地化包。新建WixExt_zh-cn.wxl文件,与Product.wxs放在同目录下即可
<?xml version="1.0" encoding="utf-8"?> <!-- <copyright file="en-us.wxl" company="Outercurve Foundation"> Copyright (c) 2004, Outercurve Foundation. This software is released under Microsoft Reciprocal License (MS-RL). The license and further copyright text can be found in the file LICENSE.TXT at the root directory of the distribution. </copyright> --> <WixLocalization Culture="zh-cn" xmlns="http://schemas.microsoft.com/wix/2006/localization"> <String Id="msierrUSRFailedUserCreate" Overridable="yes">创建用户失败。 ([2] [3] [4] [5])</String> <String Id="msierrUSRFailedUserCreatePswd" Overridable="yes">密码无效,创建用户失败。 ([2] [3] [4] [5])</String> <String Id="msierrUSRFailedUserGroupAdd" Overridable="yes">无法将用户添加到组中。 ([2] [3] [4] [5])</String> <String Id="msierrUSRFailedUserCreateExists" Overridable="yes">用户已经存在,创建用户失败。 ([2] [3] [4] [5])</String> <String Id="msierrSMBFailedCreate" Overridable="yes">无法创建网络共享。 ([2] [3] [4] [5])</String> <String Id="msierrSMBFailedDrop" Overridable="yes">无法移除网络共享。 ([2] [3] [4] [5])</String> <String Id="msierrPERFMONFailedRegisterDLL" Overridable="yes">系统监视程序中无法注册DLL. ([2] [3] [4] [5])</String> <String Id="msierrPERFMONFailedUnregisterDLL" Overridable="yes">系统监视程序中无法卸载DLL. ([2] [3] [4] [5])</String> <String Id="msierrInstallPerfCounterData" Overridable="yes">性能计数器安装失败。 ([2] [3] [4] [5])</String> <String Id="msierrUninstallPerfCounterData" Overridable="yes">无法卸载性能计数器。 ([2] [3] [4] [5])</String> <String Id="msierrSecureObjectsFailedCreateSD" Overridable="yes">无法为 [3][4]建立安全描述符, 系统错误: [2]</String> <String Id="msierrSecureObjectsFailedSet" Overridable="yes">无法在对象 [3]设置安全描述符, 系统错误: [2]</String> <String Id="msierrSecureObjectsUnknownType" Overridable="yes">未知对象类型 [3], 系统错误: [2]</String> <String Id="msierrXmlFileFailedRead" Overridable="yes">配置XML文件过程中,有一个失败。</String> <String Id="msierrXmlFileFailedOpen" Overridable="yes">打开XML文件失败 [3], 系统错误: [2]</String> <String Id="msierrXmlFileFailedSelect" Overridable="yes">在XML文件中无法找到节点: [3] : [4], 系统错误: [2]</String> <String Id="msierrXmlFileFailedSave" Overridable="yes">保存XML文件失败 [3], 系统错误: [2]</String> <String Id="msierrXmlConfigFailedRead" Overridable="yes">配置XML过程中有一处失败。</String> <String Id="msierrXmlConfigFailedOpen" Overridable="yes">打开XML失败 [3], 系统错误: [2]</String> <String Id="msierrXmlConfigFailedSelect" Overridable="yes">在XML文件中无法找到节点: [3] : [4], 系统错误: [2]</String> <String Id="msierrXmlConfigFailedSave" Overridable="yes">保存XML文件失败 [3], 系统错误: [2]</String> </WixLocalization>
备注:其它权限请参照: