【发布时间】:2011-12-25 04:43:01
【问题描述】:
我已尝试为 Visual Studio 安装程序项目创建自定义操作以修改配置文件的权限。
Installer.cs如下:
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
// Get path of our installation (e.g. TARGETDIR)
//string configPath = System.IO.Path.GetDirectoryName(Context.Parameters["AssemblyPath"]) + @"\config.xml";
string configPath = @"C:\Program Files\Blueberry\Serial Number Reservation\config.xml";
// Get a FileSecurity object that represents the current security settings.
FileSecurity fSecurity = File.GetAccessControl(configPath);
//Get SID for 'Everyone' - WellKnownSidType works in non-english systems
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
// Add the FileSystemAccessRule to the security settings.
fSecurity.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
// Set the new access settings.
File.SetAccessControl(configPath, fSecurity);
}
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
}
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
}
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
}
然后我将主输出(安装程序 class= true)添加到安装项目的自定义操作的提交部分。
当我运行安装程序时,我收到以下错误:
Error 1001: Could not find file 'c:\mypath\myapp.InstallState'
在网上搜索我发现了一些类似经历的例子,但所提供的解决方案都不适合我。
有什么想法吗?
【问题讨论】:
标签: c# windows-installer custom-action