0

我将 .dat 文件存储在ProgramData中,以编写和读取有关我的软件的配置。我会读,但我不会写。安装软件时会复制这些 .dat 文件。安装程序是使用 AwInstall 创建的。

编写.DAT的代码:

If File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) & "\NameSoftware\Configuration\paramsBiz.dat") = True Then
            Dim sw As StreamWriter = New StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) & "\NameSoftware\Configuration\paramsBiz.dat")
            sw.Write(myString)
            sw.Close()
            sw = Nothing
            Return True
        Else
            Return False
        End If

错误: 我收到此错误:

System.UnauthorizedAccessException: Acceso denegado a la ruta de acceso 'C:\ProgramData\NameSoftware\Configuration\paramsBiz.dat'.
   en System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   en System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
   en System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   en System.IO.StreamWriter.CreateFile(String path, Boolean append)
   en System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
   en System.IO.StreamWriter..ctor(String path)

更新 1:

好的,这个目录 ProgramData 有问题,正如 Hans Passant 所说

但是可以使用替代路径来存储数据,并且任何用户(管理员或非管理员)都可以读取和写入这些文件?

4

0 回答 0