Access to the Path Is Denied in Visual Studio 2010

Save

Windows 7 and Vista both include security enhancements that limit access to disk files. Unless privileges are raised with administrator access, all files other than the data in the Users folders are limited to read-access. Programs created with Visual Studio 2010 that ran fine on Windows XP may have problems when moved to Windows 7 or Vista.

The Problem

  • Windows 7 uses a security model that prevents malicious programs from modifying executable code. Only programs with administrative access are allowed to write to folders on the C: drive. Any attempt to modify other files will result in an error. Even with administrative access, Windows 7 often opens a pop-up asking if modifications can be made. The only folder where write-access can be made is the Users folder, and then only in the folder created for the currently logged-in user.

Errors in Visual Studio

  • Although most of these errors occur while running programs created by Visual Studio 2010, there are occasions when Visual Studio itself raises this error. Usually this occurs when publishing Web content. To resolve this issue, save the current project, close Visual Studio, then restart it by right-clicking on the Visual Studio icon and choose the “Run as Administrator” option. Once Visual Studio starts, open the project and publish the content.

Problems Running Programs

  • Most errors occur when running programs. Programs that write to the current folder will fail when deployed on other machines, but the framework does offer an easy way to obtain locations where data can safely be stored. The System.Environment.GetFolderPath function returns the path string to safe storage locations. To save a file in the application data folder, use:

    pathname = System.Environment.GetFolderPath (System.Environment.LocalApplicationData)

    This function also returns the locations of common application data, libraries, My Music, My Documents and a host of other locations. Here are a few other path enumeration values:

    CommonApplicationData – program data shared by all users,
    ApplicationData – user-specific application data,
    MyDocuments – user’s My Documents folder,
    MyMusic – user’s My Music folder,
    MyPictures – user’s My Pictures folder,
    Templates – location of template files,
    CommonDocuments – shared documents folder,
    CDBurning – temporary folder holding files to be burned to CD.

Raising Write Privileges

  • Windows 7 offers a way to disable these errors. When the pop-up appears, click the button labeled “Change when these errors appear” then move the slider to its maximum value. Now all programs have write-access to the entire disk drive. This is not recommended. The disk drive is now vulnerable to a number of attacks and programs created on your computer may not run on other machines. If you plan on distributing or selling your programs, take the time to change them to access safe storage.

References

Promoted By Zergnet

Comments

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!