Click here to Skip to main content
15,500,921 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
In my PC I have several drivers same C,D,E,F,... and in all I have "Program Files (x86)" in all my drivers too.
I want use SHGetFolderPathfunction as below:
C++
TCHAR szPath[MAX_PATH];

if(SUCCEEDED(SHGetFolderPath(NULL, 
                             CSIDL_PROGRAM_FILESX86|CSIDL_FLAG_CREATE, 
                             NULL, 
                             0, 
                             szPath))) 
{
    PathAppend(szPath, TEXT("New Doc.txt"));
    HANDLE hFile = CreateFile(szPath, ...);
}


Question is here:
How use this that search and find all drives and run this function for all my drives?

Regards,
Posted

According to MSDN you can have one valid Program Files folder for one OS boot mode.


Here, is how the actual structure of Program Files look like.
GUID {905e63b6-c1bf-494e-b29c-65b732d3d21a}
Display Name Program Files
Folder Type FIXED
Default Path %ProgramFiles% (%SystemDrive%\Program Files)
CSIDL Equivalent CSIDL_PROGRAM_FILES
Legacy Display Name Program Files
Legacy Default Path %ProgramFiles% (%SystemDrive%\Program Files)

and for a 64 bit machine following are the options available.

OS Application KNOWNFOLDERID Default Path CSIDL Equivalent
32 bit 32 bit FOLDERID_ProgramFiles %SystemDrive%\Program Files CSIDL_PROGRAM_FILES
32 bit 32 bit FOLDERID_ProgramFilesX86 %SystemDrive%\Program Files CSIDL_PROGRAM_FILESX86
32 bit 32 bit FOLDERID_ProgramFilesX64 (undefined) Not applicable Not applicable

Seems, you are having different OS boot options and these OS have ProgramFiles in different Drives. So, depending upon which OS you have used to boot the path CSIDL_PROGRAM_FILESX86 will point to corresponding GUID of that folder in the registry. You might want to iterate through folders of different drives inorder to get all program files folders in your system.

You might want to have a look on FindFirstFile API and iterate only folders (using a customized function to differentiate between file and folder eg. boost::filesystem::is_directory())with it and compare the name to the Folder name you are searching for.


Cheers
Kushagra
 
Share this answer
 
v2
Comments
Rezame 11-Aug-13 5:32am    
For default there is one Program Files folder in each PC, but I create manually that folder when install new software. So I have more Program files Folder.
Kushagra Tiwari 11-Aug-13 6:19am     CRLF
You might want to have a look on FindFirstFile API and iterate only folders (using a customized function to differentiate between file and folder eg. boost::filesystem::is_directory())with it and compare the name to the Folder name you are searching for. Hope this helps. Please rate the solution if it was helpful Cheers Kushagra
I don't know why do you have more than one program files directory on many drives (maybe because of transferring hard drives between machines) but normally you should have only one such directory in your system and that directory is returned by the SHGetFolderPath() that you already found out. On 64 bit windows systems you can have two directories: A "Program Files (x86)" for 32 bit applications and a "Program Files" directory for the 64 bit ones.
 
Share this answer
 
Comments
Rezame 11-Aug-13 5:32am    
For default there is one Program Files folder in each PC, but I create manually that folder when install new software. So I have more Program files Folder.
pasztorpisti 11-Aug-13 7:28am    
Still, you windows will keep account only one of these folders as "official" folder. Many installers ask you for an installation directory and these installers will ask windows for the "official" Program Files folder.
Why not use GetLogicalDrive() to get all drive letters, and append the "Program Files (x86)" on each of them, then you can get the file paths.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900