ProgramData. Access denied (VB.NET 2008)

767 views Asked by At

I am storing .dat files in ProgramData to write and read configurations about my software. I can read, but I can't write. These .dat files are copied when software is installed. The installer has been created with AwInstall.

CODE TO WRITE .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

ERROR: I am getting this error:

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)

UPDATE 1:

ok, is a problem with this directory ProgramData, as has been said Hans Passant

But alternative path could be used to store data and that any user (admin or not) can read and write these files?

0

There are 0 answers