locked
Error System.UnauthorizedAccessException in mscorlib.dll("Access to path...." is denied.) RRS feed

  • Question

  • I have an application, that I let users back up data to a zip file. When the user tries to do a "Restore" of this data(basically just coping files from the zip file to the application directory) I get the error I posted in the title.

    What are some ways of taking care of this?

    Some ideas I had, was to modify the folder security to allow the user to copy the data to the app folder.. which resides under "Program files". Not sure how to do that.

    or notify the user that they need to run the app "As Administrator" ... My program is packaged with install shield lite and puts an icon on the desktop....  When I right click on the icon, there is no option to run "As Administrator". 

    Any thoughts, idea's or help would be great.

    Thanks

    Saturday, June 25, 2016 2:50 AM

Answers

  • Some ideas I had, was to modify the folder security to allow the user to copy the data to the app folder.. which resides under "Program files". Not sure how to do that.

    The Programdata folder is the all users folder on the O/S(s) in the link, which is a hidden folder that you must unhide to see the content of the folder where you will find 3rd party programs place data files that a program needs to due CRUD operation with a data file in the folder. It is wide open to any program running under the context of a Standard user account. But it doesn't need t be unhidden to access the folder.

    https://technet.microsoft.com/en-us/library/ff716245.aspx

    <copied>

    ProgramData specifies the path to the program-data folder (normally C:\ProgramData). Unlike the Program Files folder, this folder can be used by applications to store data for standard users, because it does not require elevated permissions.

    <end>

    The appdata folder is a user folder specific to a user's profile that can log into the machine, and you don't see 3rd party vendor programs placing data files that the 3rd party program needs in an appdata folder, because all users that logged into the machine to run the program that accesses the files must have access to the files.  ProgramData  is the folder that is the all users folder, just like it is being used on XP and Win 2k3 server and down where the folder is actually named  AllUsers, but now it is called ProgramData folder that is on Win 10 too.

    • Marked as answer by LandLord324 Sunday, June 26, 2016 2:50 AM
    Sunday, June 26, 2016 1:26 AM

All replies

  • What folder are you putting the files into? Don't use the programs folder (you don't have permission). When saving user data, use the user area like app\data. ie:

     'get the app data folder on local system
      datadir = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\Sandia_Software\Update"
    
      'create the folder
      System.IO.Directory.CreateDirectory(datadir)


    Saturday, June 25, 2016 7:52 PM
  • Since Windows 7 already is the Program Files folder a restricted folder. 

    You can ask the end user to modify the folder security. But that is the same likewise to ask them to keep always their key in the lock of their door. 

    Simply don't use the program files folders anymore for read and write. 

    Tommy gave you a way to do that. 


    Success
    Cor


    Saturday, June 25, 2016 8:05 PM
  •  As was said,  Tom has given you a way to get the ApplicationData folder path which is what you should use.  I would only add the following,  don`t use the + sign to join Strings together,  use the & character instead.

     Better yet,  use the Path.Combine Method to combine Directories and Filenames together.  This is because,  not all systems use a backslash "\" character as a directory separator and the Path.Combine method will assure that the correct directory separator is used for the system it is ran on when they are combined.

     


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Saturday, June 25, 2016 9:54 PM
    Saturday, June 25, 2016 8:55 PM
  • Some ideas I had, was to modify the folder security to allow the user to copy the data to the app folder.. which resides under "Program files". Not sure how to do that.

    The Programdata folder is the all users folder on the O/S(s) in the link, which is a hidden folder that you must unhide to see the content of the folder where you will find 3rd party programs place data files that a program needs to due CRUD operation with a data file in the folder. It is wide open to any program running under the context of a Standard user account. But it doesn't need t be unhidden to access the folder.

    https://technet.microsoft.com/en-us/library/ff716245.aspx

    <copied>

    ProgramData specifies the path to the program-data folder (normally C:\ProgramData). Unlike the Program Files folder, this folder can be used by applications to store data for standard users, because it does not require elevated permissions.

    <end>

    The appdata folder is a user folder specific to a user's profile that can log into the machine, and you don't see 3rd party vendor programs placing data files that the 3rd party program needs in an appdata folder, because all users that logged into the machine to run the program that accesses the files must have access to the files.  ProgramData  is the folder that is the all users folder, just like it is being used on XP and Win 2k3 server and down where the folder is actually named  AllUsers, but now it is called ProgramData folder that is on Win 10 too.

    • Marked as answer by LandLord324 Sunday, June 26, 2016 2:50 AM
    Sunday, June 26, 2016 1:26 AM
  • thanks... I'll modify my program to look at ProgramData folder, that way, its not limited to user.
    Sunday, June 26, 2016 2:51 AM
  • thanks... I'll modify my program to look at ProgramData folder, that way, its not limited to user.
    I am glad I can help.
    Sunday, June 26, 2016 3:20 AM