Suddenly Occurring Access Denied Problem

I have used the attached code for several years without problem. However, after compiling and installing with VS 2010 I get an access denied error when trying to write to the program directory where the program is installed. I need to be able to write to the application path to save an XML file and also to the Statistical Audits sub directory. Any suggestions on why this has suddenly appeared would be appreciated.

OS: Windows 7 (Note: this has worked on XP, Vista and Windows 7 up until I did a recompile today with changes unrelated to this area.)
gAppPath = System.Windows.Forms.Application.StartupPath

            If Not My.Computer.FileSystem.DirectoryExists(gAppPath & "\Statistical Audits") Then
                My.Computer.FileSystem.CreateDirectory(gAppPath & "\Statistical Audits")
            End If
            Try
                My.Computer.FileSystem.WriteAllText(gAppPath & "\Statistical Audits\Seed Log.txt", SeedRecord, True)
            Catch ex As Exception
                gMsg = "The following error occurred when trying to save the seed: " & vbCrLf & ex.Message & vbCrLf & "You will have to save the seed manually in order to reproduce or expand the sample."
                MsgBox(gMsg, MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Error Saving Seed")
            End Try

Open in new window

LVL 1
rkulpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

xav056Commented:
when you did the recompile where you running as an admin?
0
rkulpAuthor Commented:
xav056,

Yes. But I was on previous compiles.
0
rkulpAuthor Commented:
The real question is how to ensure the program has the rights to write to that directory on any user's computer. There are about 100 users who have never complained about this error.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

xav056Commented:
can you check the security permission on the directory/file you are trying to write to, in the application where you have the permission issues as weel as where the application runs fine
0
rkulpAuthor Commented:
I recompiled using VS2005 and the problem went away. Now I have to figure out what to do when I begin using VS 2010 instead of Vs2005. I'll try to bring it up during the launch events on Monday, April 12. I'll report what the VS team has to say.
0
CodeCruiserCommented:
I believe that you get this problem on Win7/Vista machines. Win7/Vista do not allow programs to write to most folders in the system drive(driver root, windows folder, program files folder etc).
0
CodeCruiserCommented:
>I'll try to bring it up during the launch events on Monday, April 12.

In broadway shopping centre on Fulham Road?
0
rkulpAuthor Commented:
Code Cruiser,

I have been able to write to these folders on XP, Vista and Windows 7 until I compiled with VS 2010.

Unfortunately, I'll have to join in the festivities online. Not nearly as much fun as the shopping centre on Fulham Road.
0
CodeCruiserCommented:
Have you check the permissions?

I am going in person to attend the lauch. Catching the 6:21 train tomorrow morning from Derby to London. Staying at a hotel in Chelsea football ground.
0
rkulpAuthor Commented:
Yes. At any rate, why would it change when compiled on the same computer as before and tested on the same computer which happened to be the development machine?

I hope you have a great time in London. It's been about 30 years since I have been in England.
0
rkulpAuthor Commented:
Since no experts were in the "Ask the Experts" chat room this afternoon, at least for the first 30 minutes, I was not able to get an answer. However, it seems I need to put the files in an area where the program can read/write regardless of who is logged on and what his/her privileges are. What is the best way to do that? If I use
 
     gAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

I get something like

     C:\users\loggedonusername\AppData\Roaming

Will this work if a different user logs on? Is there a better way?
0
CodeCruiserCommented:
App data folder is different for each user. Your program should be able to write to this folder.
0
rkulpAuthor Commented:
I really need a single place for every user. I'll probably end up creating a folder for the app on the installation drive.
0
CodeCruiserCommented:
The system drive root also requires admin mode to write. Try the allusers appdata folder.
0
rkulpAuthor Commented:
Thanks. I'll try that. I'm out of pocket until Monday so will respond then.
0
rkulpAuthor Commented:
Well, I discovered

Environment.SpecialFolder.CommonApplicationData

which provides access to the ProgramData directory. I have successfully added a sub directory for my app and written data to it. This should solve my problem. Thanks for all your help.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodeCruiserCommented:
Glad that your problem is sorted :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.