Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to obtain a special folder path for ANY user?

How to obtain a special folder path for ANY user?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialwindows-adminjsonquestion
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bila1
    wrote on last edited by
    #1

    Hi all, I would like to know if there is a way to programmatically obtain the path to any user's any special folder? Here I do not mean "All users" profile but really for any user that has his/her profile created on the machine. For example, I can get what I need with the "SHGetSpecialFolderPath" function, but only for the current user. I need to do the same thing but for any arbitrary user. If this task can not be achieved with SHGetSpecialFolderPath function or any other API function, is there maybe some workaround (like manually reading specific registry keys and values)? Thanks in advance. Bila

    D 1 Reply Last reply
    0
    • B Bila1

      Hi all, I would like to know if there is a way to programmatically obtain the path to any user's any special folder? Here I do not mean "All users" profile but really for any user that has his/her profile created on the machine. For example, I can get what I need with the "SHGetSpecialFolderPath" function, but only for the current user. I need to do the same thing but for any arbitrary user. If this task can not be achieved with SHGetSpecialFolderPath function or any other API function, is there maybe some workaround (like manually reading specific registry keys and values)? Thanks in advance. Bila

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Bila1 wrote:

      For example, I can get what I need with the "SHGetSpecialFolderPath" function, but only for the current user.

      Use SHGetFolderPath() instead.


      "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

      "Judge not by the eye but by the heart." - Native American Proverb

      B 1 Reply Last reply
      0
      • D David Crow

        Bila1 wrote:

        For example, I can get what I need with the "SHGetSpecialFolderPath" function, but only for the current user.

        Use SHGetFolderPath() instead.


        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

        "Judge not by the eye but by the heart." - Native American Proverb

        B Offline
        B Offline
        Bila1
        wrote on last edited by
        #3

        Thanks for your reply. I have already tried this function, but I do not know how to use it to get what I need. I guess that the "hToken" parameter is the answer. Problem is, I do not know the process to create such a token (access token). Could you help me further with this issue please? Bila

        D 1 Reply Last reply
        0
        • B Bila1

          Thanks for your reply. I have already tried this function, but I do not know how to use it to get what I need. I guess that the "hToken" parameter is the answer. Problem is, I do not know the process to create such a token (access token). Could you help me further with this issue please? Bila

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Bila1 wrote:

          I guess that the "hToken" parameter is the answer. Problem is, I do not know the process to create such a token (access token).

          You can use LogonUser() to retrieve the token.


          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

          "Judge not by the eye but by the heart." - Native American Proverb

          B 1 Reply Last reply
          0
          • D David Crow

            Bila1 wrote:

            I guess that the "hToken" parameter is the answer. Problem is, I do not know the process to create such a token (access token).

            You can use LogonUser() to retrieve the token.


            "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

            "Judge not by the eye but by the heart." - Native American Proverb

            B Offline
            B Offline
            Bila1
            wrote on last edited by
            #5

            Thanks, this sure helps. Now, one more twist: is there any other way I can do what I need -without- requiring the user's password?

            S D 2 Replies Last reply
            0
            • B Bila1

              Thanks, this sure helps. Now, one more twist: is there any other way I can do what I need -without- requiring the user's password?

              S Offline
              S Offline
              Sheng Jiang
              wrote on last edited by
              #6

              You may read them under HKEY_USERS, but it is not suggested. Some keys are not created until the special folder path is requested by the user, and you may not have the permission to read these entries.

              Regards Microsoft MVP in Visual C++ www.jiangsheng.net

              B 1 Reply Last reply
              0
              • B Bila1

                Thanks, this sure helps. Now, one more twist: is there any other way I can do what I need -without- requiring the user's password?

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                Bila1 wrote:

                ...is there any other way I can do what I need -without- requiring the user's password?

                Yes, but it's a bit more involved. You'll need to iterate through the folders in the following registry key: HKEY_USERS\xxxx\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders You'll need to loop through the users to find the right one (SID).


                "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                "Judge not by the eye but by the heart." - Native American Proverb

                B 1 Reply Last reply
                0
                • S Sheng Jiang

                  You may read them under HKEY_USERS, but it is not suggested. Some keys are not created until the special folder path is requested by the user, and you may not have the permission to read these entries.

                  Regards Microsoft MVP in Visual C++ www.jiangsheng.net

                  B Offline
                  B Offline
                  Bila1
                  wrote on last edited by
                  #8

                  Hi, I already tried this approach but no success. Reason is that there are no keys in HKEY_USERS hive for any other users beside the current user and some system users (NETWORK SERVICE, LOCAL SERVICE if I remember correctly). If the problem is really with access permissions, is there a way to obtain them so I can read this hive? Maybe some workaround? Or for that reason, any other way at all to find out a special folder for any other user (I specifically need the startup folder)? Thanks. Bila -- modified at 3:56 Tuesday 24th October, 2006

                  1 Reply Last reply
                  0
                  • D David Crow

                    Bila1 wrote:

                    ...is there any other way I can do what I need -without- requiring the user's password?

                    Yes, but it's a bit more involved. You'll need to iterate through the folders in the following registry key: HKEY_USERS\xxxx\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders You'll need to loop through the users to find the right one (SID).


                    "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                    "Judge not by the eye but by the heart." - Native American Proverb

                    B Offline
                    B Offline
                    Bila1
                    wrote on last edited by
                    #9

                    I already implemented this approach, but it does not give satisfying results (please see my reply to Jiang Sheng above). Any other suggestion?

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups