我在WiX中运行C#自定义操作:
[CustomAction]
public static ActionResult SetAppDataSecurity(Session session)
{
session.Log("Running security...");
session.Log("Creating dInfo...");
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + Path.DirectorySeparatorChar + "MyApp");
session.Log("dInfo.FullName is " + dInfo.FullName);
session.Log("dInfo.Exists is " + dInfo.Exists);
session.Log("Creating dSecurity...");
// Get a DirectorySecurity object that represents the current security settings.
DirectorySecurity dSecurity = dInfo.GetAccessControl();
session.Log("dSecurity ACL count is " + dSecurity.GetAccessRules(true, true, Type.GetType("System.Security.Principal.SecurityIdentifier")).Count);
session.Log("dSecurity.AddAccessRule...");
// Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(new FileSystemAccessRule("Authenticated Users", FileSystemRights.Write, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
session.Log("dInfo.SetAccessControl...");
// Set the new access settings.
dInfo.SetAccessControl(dSecurity);
session.Log("dSecurity ACL count is " + dSecurity.GetAccessRules(true, true, Type.GetType("System.Security.Principal.SecurityIdentifier")).Count);
session.Log("SetAppDataSecurity done.");
return ActionResult.Success;
}
我的安装程序正在另一台机器上调用它 - 这是msiexec日志:
Action ended 23:24:56: InstallFinalize. Return value 1.
MSI (s) (78:F0) [23:24:56:518]: Doing action: SetAppDataSecurity
MSI (s) (78:F0) [23:24:56:518]: Note: 1: 2205 2: 3: ActionText
Action 23:24:56: SetAppDataSecurity.
Action start 23:24:56: SetAppDataSecurity.
MSI (s) (78:70) [23:24:56:612]: Invoking remote custom action. DLL: C:\Windows\Installer\MSICC37.tmp, Entrypoint: SetAppDataSecurity
SFXCA: Extracting custom action to temporary directory: C:\Users\EDIT~1\AppData\Local\Temp\abcdef.tmp-\ //edited
SFXCA: Binding to CLR version v4.0.30319
Calling custom action WiXCustomActions!WiXCustomActions.CustomActions.SetAppDataSecurity
Running security...
Creating dInfo...
dInfo.FullName is C:\ProgramData\MyApp
dInfo.Exists is True
Creating dSecurity...
dSecurity ACL count is 6
dSecurity.AddAccessRule...
dInfo.SetAccessControl...
dSecurity ACL count is 7
SetAppDataSecurity done.
Action ended 23:24:57: SetAppDataSecurity. Return value 1.
Action ended 23:24:57: INSTALL. Return value 1.
当我查看该文件夹时,未使用"经过身份验证的用户"设置其安全性。
以前的安装和部署项目中使用了相同的代码并且工作正常,并添加了具有写权限的Authenticated Users组。