locked
Checking System Folder Permissions: RRS feed

  • Question

  •  

    I have a process that "could" require elevation based on the location of certain data files. (the files are from antoher application that's requiring the user to run elevated.)

     

    If the data files are in a system location, i.e. <Program Files> or <Windows> I would need to elevate the process in order to ensure it had the necessary rights to update those files. However, if they aren't in a system location, elevation would be unnecessary, (as would forcing the user to elevate.)

     

    Is there a way (without trying to create files) I can programmatically check to see if the user will need to elevate in order to write to a certain path?

     

    Regards,

     

    - Aaron.

    Monday, July 23, 2007 4:07 PM

Answers

  •  AaronY77 wrote:

    Thanks for the response, but the problem isn't with opening/reading the file its with writing and it seems like there should be a more elegant solution than attempting the operation and seeing if it fails

    It might seem like that, but there isn't. Doing so would be as flawed as the IsBadXxxPtr functions, for most of the same reasons. The only reliable way to implement an access check is to attempt the operation and then deal with the result appropriately.
    Friday, July 27, 2007 7:42 AM

All replies

  • The best way to do this is to attempt to open the file and then fall back to using elevation if you get an Access Denied.
    Tuesday, July 24, 2007 4:48 AM
  • Thanks for the response, but the problem isn't with opening/reading the file its with writing and it seems like there should be a more elegant solution than attempting the operation and seeing if it fails.

     

    Surely if Microsoft is going to enforce certain security rules, shouldn't they provide means by which to test those rules?

     

    - Aaron.

     

    Thursday, July 26, 2007 4:29 PM
  •  AaronY77 wrote:

    Thanks for the response, but the problem isn't with opening/reading the file its with writing and it seems like there should be a more elegant solution than attempting the operation and seeing if it fails

    It might seem like that, but there isn't. Doing so would be as flawed as the IsBadXxxPtr functions, for most of the same reasons. The only reliable way to implement an access check is to attempt the operation and then deal with the result appropriately.
    Friday, July 27, 2007 7:42 AM