开发者

Access error in Windows 7

I am working on a windows appliciation in which i create a folder at runtime and save some xml files in the folder.... Every thing works fine in Windows XP but when i run this in Widows 7开发者_开发知识库 / Vista i get the error saying Access to the path is denied.. i am creating the folder in C:\Programfiles\MyApplication\

Please help me in resolving this


Windows 7 (and Vista) set access permissions on the Program Files directories and will not allow a normal user to write to those directories.

Either your program has to be run by an administrator, or you can change the permissions on your app's Program Files entry, or save the data somewhere else.


It might be an idea to use the special folders .NET provides for this type of data. This should work:

Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\AppName\test folder");

Then write your data to this folder.


  • Is your application running in the context of administrator?

  • Is visual studio running as administrator?

To do this right click VS and select run as administrator, to do it permanently, right click, propertys and select the run as admin check box.

When your debugging your app through VS, it will need the permissions, else the application its self will.

Its probably just a permissions based thing...


You can enable XP mode for an executable.


Please find the settings below

link text


Long time Windows XP developers should consider reading UAC,

http://en.wikipedia.org/wiki/User_Account_Control

It was first added in Windows Vista, and now becomes a central part of Windows family.


You SHOULDN'T write to Program Files. It's a bad habit and only installers should write there. What you "want" is bad for the whole ecosystem and just plain wrong. Don't do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜