How to get currently windows logged on users profile directory.
-
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
-
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
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:
-
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:
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
-
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
WindowsPistha wrote:
Both gives administrator profile directory only, if elevated.
What did you use as the fourth argument (i.e.,
dwFlags
) toSHGetFolderPath()
?"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
-
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
Any help here? Per-user Installations[^]
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
WindowsPistha wrote:
Both gives administrator profile directory only, if elevated.
What did you use as the fourth argument (i.e.,
dwFlags
) toSHGetFolderPath()
?"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
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
-
Any help here? Per-user Installations[^]
Mark Salsbery Microsoft MVP - Visual C++ :java:
Thanks ! I have red the link. SHGetKnownFolderPath also gives me the admin users appdata path. Not the currently windows logged in users appdata path.
-
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
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