Acess否认。读写文件。授予阅读权限

时间:2015-05-01 06:39:36

标签: c# .net visual-studio-2012 .net-4.0

安装后,应用程序出错

  

拒绝访问文件PathName\\BLsms.ocx

这里PatheName是完整路径。

高级安装程序用于创建安装程序。

然后,应用程序安装在C Drive

如何使这些文件可读写?

我正在使用此代码。

try
{

    this.brlmfc = new BinaryReader(new FileStream("BLsms.ocx", FileMode.Open, FileAccess.ReadWrite,FileShare.Read));
    this.brocx = new BinaryReader(new FileStream("BLrpi.lfc", FileMode.Open,FileAccess.ReadWrite));

    this.brlmc = new BinaryReader(new FileStream("rpcgh.lfc", FileMode.Open,FileAccess.ReadWrite));
    this.passkey1 = this.brlmfc.ReadString();
    this.passkey2 = this.brocx.ReadString();

    this.passkey3 = this.brlmc.ReadString();

}
catch (Exception e13)
{
    MessageBox.Show(e13.Message);
    i = 0;
}

我还在Form Load方法中尝试了以下代码。

FileIOPermission f2 = new FileIOPermission(FileIOPermissionAccess.AllAccess, Application.StartupPath+"\\BLsms.ocx");
f2.AddPathList( FileIOPermissionAccess.Read, Application.StartupPath+"\\BLrpi.lfc");
f2.AddPathList( FileIOPermissionAccess.Read, Application.StartupPath+"\\Brpcgh.lfc");
f2.Demand();

2 个答案:

答案 0 :(得分:2)

我假设您要将程序安装到C:\Program FilesC:\Program Files (x86)。不要写在那些目录中。请改用C:\ProgramData或用户的主目录。

答案 1 :(得分:1)

我已经设置了来自Advance Installer的文件的读/写权限。工作正常。

http://www.advancedinstaller.com/user-guide/permission-dialog.html

谢谢大家。

相关问题