access to the path "..." is denied.

I created a windows service project in visual studio 2005 using vb.net 2.0.  I have a Textboxes (A) add to the custom actions so the person doing the install can input an account key.  In my ProjectInstaller_BeforeInstall event handler I get the account key and write it to a file using:  
My.Computer.FileSystem.WriteAllText(My.Application.Info.DirectoryPath & "\cnxGZMON.config", sAccountKey, False)

After the service is started I can read the file OK and I get my account key OK using:  
My.Settings.AccountKey = Trim(My.Computer.FileSystem.ReadAllText(My.Application.Info.DirectoryPath & "\cnxGZMON.config"))

 The problem comes when I modify the account key and write it back to the file using:  
My.Computer.FileSystem.WriteAllText(My.Application.Info.DirectoryPath & "\cnxGZMON.config", sAccountKey, False)  (i.e., the save code as the original write above).  When I attempt this write I get an error:  
System.UnauthorizedAccessException--Access to the path 'C:\Program Files\Convina\cnxGZMONsetup\cnxGZMON.config' is denied.
cnxmaxAsked:
Who is Participating?
 
Joel CoehoornConnect With a Mentor Director of Information TechnologyCommented:
The Program Files folder, and all sub folders, are read only to standard users.  This is by design.  Instead, use the application data folder:

        My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData
or
        My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
0
 
cnxmaxAuthor Commented:
bingo.  danka.
0
All Courses

From novice to tech pro — start learning today.