dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: File Explorer application permissions

  1. #1
    Join Date
    Sep 2018
    Posts
    38

    File Explorer application permissions

    I just finished reading an article on the site here, and put together an app that is a File Explorer type application. I've got the application to compile and run, but I'm having a problem with permissions. When I click on a node in the TreeView for a directory, my application breaks and says I don't have permissions to access the directories. I'm really not familiar with handling file permissions progromatically, so I'm looking for information on how to approach this obstacle.

    Any information is welcome on how I can integrate an in-line permission in my form file to have access as needed. Thanks!

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,808

    Re: File Explorer application permissions

    If you are running the app from Visual Studio, try running VIsual Studio as an administrator. If you are running your app stand-a-lone, run the app as an admin. Report back here with the results.

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,487

    Re: File Explorer application permissions

    Even as an admin, you may still need to acquire Backup Privilege to enable read access to any file. See https://docs.microsoft.com/en-us/win...lege-constants
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.8.9)

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,808

    Re: File Explorer application permissions

    Quote Originally Posted by 2kaud View Post
    Even as an admin, you may still need to acquire Backup Privilege to enable read access to any file. See https://docs.microsoft.com/en-us/win...lege-constants
    There is a more direct way of elevating process privileges in .net.

  5. #5
    Join Date
    Sep 2018
    Posts
    38

    Re: File Explorer application permissions

    The solution to this turns out to be what you suggested Arjay. I read an article that suggested checking out the application properties and found the program manifest. It had comments on it that showed what to change in order to run my app as an administrator. For those looking for the same solution and in Visual Studio 2017, go to the Properties of your app, open the Application tab, choose View Window Settings. There will be comments on the code page that show how to make changes to run as administrator. The line you want to change your manifest to is:

    Code:
    <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
    Visual Studio will restart and then run your app as Administrator.

    The question I'm wondering about now is what happens when someone else runs the app on another pc. If they are the admin, then I suppose it will run, but what if they are a user logged on that doesn't have that permission? Will the app not run?

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,808

    Re: File Explorer application permissions

    Does your file explorer app need access to the whole file system or just a part of it (like where users store files)? If it needs access to the whole of it, then the user will be prompted to run as an admin, and if the don't have admin permissions, they won't be able to run the app. However, users have access to parts of the file system to be able to store data without requiring elevated privileges. If your app can work within this restriction, it won't need elevated admin permissions.

    See Environment.GetFolderPath in msdn.
    Last edited by Arjay; October 16th, 2018 at 03:55 AM.

  7. #7
    Join Date
    Sep 2018
    Posts
    38

    Re: File Explorer application permissions

    The code I've used from the article specifies any directory under the C:\ drive. I suspect in the future as I work with this I'll draw in all drives, which from what you say means a user will have to have admin permission. But then a more sophisticated code probably sorts out other permissions and accounts for them. This is over in the future for me, but I imagine something I'll be contending with. I'd be curious to hear your thoughts on designing a file application that takes into account other users without elevated permissions. I suppose anything dealing with security is complex. Feel free to share any thoughts you may have on this. I've found several articles on this site through a basic search online that have been very helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)