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 get currently windows logged on users profile directory.

How to get currently windows logged on users profile directory.

Scheduled Pinned Locked Moved C / C++ / MFC
workspacetutorial
8 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.
  • W Offline
    W Offline
    WindowsPistha
    wrote on last edited by
    #1

    Hello friends, I want to develope a software which can run for standard users. My software will be installed for only for current user. My superior wants me to keep read only files(Exe ,Dlls...) in Program files path. Other data files in Appdata path,Since those files required Read & write access. Ex: Lets consider two user accounts in a PC. 1) administrator 2) joe ( standard user) Now the user logged in as a joe and trying to install the software. So my setup file asks for elevation becoz it has to put files in program files path. Once the installer has got elevated ,after that if i am getting Environment variable "AppData" to put the data files. It gives me "C:\users\administrator\Appdata\Roaming\" path, but actually i have to put the files for user joe. I dont know how to get the currently logged in users Profile directory. Note: After the elevation . if I am getting the HKCU profile that also gives me the administrator profile only. Try outs: I was loggin as a Joe ( standard user)and launching the setup file.Setup file asks for elevation. From My setup file(runs in administrator account after elevation), I tried to find "expolrer.exe" (runs in Joe account) and getting it is ProcessToken and CreateEnvironmentBlock fn to create environment block for the Explorer.exe. In Vista it is succeeding but in XP OpenProcess fails if i am elevating the exe and trying to get info from the Explorer.exe which runs in Joe's account.

    HANDLE hProcessHandle = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,dwExploererProcessId);

    if( hProcessHandle == NULL)
    	return -2; 
    
    int nRetVal = OpenProcessToken(hProcessHandle,TOKEN\_QUERY,&hToken);	
    
    
    if(nRetVal == 0 )
    	return -3;
    
    BOOL bval = CreateEnvironmentBlock(&lpData,hToken,FALSE);
    
    if(bval == FALSE)
    	return -4;
    

    Advice me about the correct way to get the Currently logged in users profile directory. Eagerly waiting for your answers. Thanks , WindowsPistha

    M 1 Reply Last reply
    0
    • W WindowsPistha

      Hello friends, I want to develope a software which can run for standard users. My software will be installed for only for current user. My superior wants me to keep read only files(Exe ,Dlls...) in Program files path. Other data files in Appdata path,Since those files required Read & write access. Ex: Lets consider two user accounts in a PC. 1) administrator 2) joe ( standard user) Now the user logged in as a joe and trying to install the software. So my setup file asks for elevation becoz it has to put files in program files path. Once the installer has got elevated ,after that if i am getting Environment variable "AppData" to put the data files. It gives me "C:\users\administrator\Appdata\Roaming\" path, but actually i have to put the files for user joe. I dont know how to get the currently logged in users Profile directory. Note: After the elevation . if I am getting the HKCU profile that also gives me the administrator profile only. Try outs: I was loggin as a Joe ( standard user)and launching the setup file.Setup file asks for elevation. From My setup file(runs in administrator account after elevation), I tried to find "expolrer.exe" (runs in Joe account) and getting it is ProcessToken and CreateEnvironmentBlock fn to create environment block for the Explorer.exe. In Vista it is succeeding but in XP OpenProcess fails if i am elevating the exe and trying to get info from the Explorer.exe which runs in Joe's account.

      HANDLE hProcessHandle = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,dwExploererProcessId);

      if( hProcessHandle == NULL)
      	return -2; 
      
      int nRetVal = OpenProcessToken(hProcessHandle,TOKEN\_QUERY,&hToken);	
      
      
      if(nRetVal == 0 )
      	return -3;
      
      BOOL bval = CreateEnvironmentBlock(&lpData,hToken,FALSE);
      
      if(bval == FALSE)
      	return -4;
      

      Advice me about the correct way to get the Currently logged in users profile directory. Eagerly waiting for your answers. Thanks , WindowsPistha

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      WindowsPistha wrote:

      Advice me about the correct way to get the Currently logged in users profile directory.

      Maybe use SHGetFolderPath(), or on Vista+ only, SHGetKnownFolderPath(). Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      W 1 Reply Last reply
      0
      • M Mark Salsbery

        WindowsPistha wrote:

        Advice me about the correct way to get the Currently logged in users profile directory.

        Maybe use SHGetFolderPath(), or on Vista+ only, SHGetKnownFolderPath(). Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        W Offline
        W Offline
        WindowsPistha
        wrote on last edited by
        #3

        Both i tried SHGetFolderPath(), or on Vista+ only, SHGetKnownFolderPath(). Both gives administrator profile directory only, if elevated.

        modified on Thursday, October 30, 2008 2:42 PM

        D M 2 Replies Last reply
        0
        • W WindowsPistha

          Both i tried SHGetFolderPath(), or on Vista+ only, SHGetKnownFolderPath(). Both gives administrator profile directory only, if elevated.

          modified on Thursday, October 30, 2008 2:42 PM

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

          WindowsPistha wrote:

          Both gives administrator profile directory only, if elevated.

          What did you use as the fourth argument (i.e., dwFlags) to SHGetFolderPath()?

          "Love people and use things, not love things and use people." - Unknown

          "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

          W 1 Reply Last reply
          0
          • W WindowsPistha

            Both i tried SHGetFolderPath(), or on Vista+ only, SHGetKnownFolderPath(). Both gives administrator profile directory only, if elevated.

            modified on Thursday, October 30, 2008 2:42 PM

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            Any help here? Per-user Installations[^]

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            W 1 Reply Last reply
            0
            • D David Crow

              WindowsPistha wrote:

              Both gives administrator profile directory only, if elevated.

              What did you use as the fourth argument (i.e., dwFlags) to SHGetFolderPath()?

              "Love people and use things, not love things and use people." - Unknown

              "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

              W Offline
              W Offline
              WindowsPistha
              wrote on last edited by
              #6

              I used SHGFP_TYPE_CURRENT flag that also gives me the elvated users app data path.

              modified on Friday, October 31, 2008 6:36 AM

              D 1 Reply Last reply
              0
              • M Mark Salsbery

                Any help here? Per-user Installations[^]

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                W Offline
                W Offline
                WindowsPistha
                wrote on last edited by
                #7

                Thanks ! I have red the link. SHGetKnownFolderPath also gives me the admin users appdata path. Not the currently windows logged in users appdata path.

                1 Reply Last reply
                0
                • W WindowsPistha

                  I used SHGFP_TYPE_CURRENT flag that also gives me the elvated users app data path.

                  modified on Friday, October 31, 2008 6:36 AM

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

                  Have you tried SHGFP_TYPE_DEFAULT to see if it yields anything different?

                  "Love people and use things, not love things and use people." - Unknown

                  "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                  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