This is Rust program that reports information from multiple sources about where program files directories are located on a Windows system.
Details on the source of information, including on subtleties of availability across process and system architectures, are provided in the code on the four report_* functions that access them. This is a brief summary of the functions:
-
report_environment_variables()uses theProgramFiles,ProgramFilesW6432,ProgramFiles(x86), andProgramFiles(ARM)environment variables.It calls
std::env::var()which, on Windows, itself internally calls theGetEnvironmentVariableWfunction. -
report_known_folders()uses theProgramFiles,ProgramFilesX64,ProgramFilesX86, andUserProgramFilesknown folders. (See also these remarks.)It calls
SHGetKnownFolderPathin the Windows API using thewindowscrate, which allows detailed errors to be reported, and for demonstration purposes also calls and checks those results against theget_known_folder_path()function provided by theknown-folderscrate, which is often sufficient. -
report_csidl()uses theCSIDL_PROGRAM_FILESandCSIDL_PROGRAM_FILESX86CSIDLs, though this should not usually be done because CSIDLs are superseded by known folders.It calls
SHGetFolderPathWin the Windows API using thewindowscrate. -
report_all_registry_views()(see alsoreport_registry_view()) uses theProgramFilesDir,ProgramW6432Dir,ProgramFilesDir (x86), andProgramFilesDir (Arm)registry keys inHKLM\SOFTWARE\Microsoft\Windows\CurrentVersion, showing their values when accessed through the default view of the registry that depends on the process architecture, as well as when explicitly specifying the 32-bit view withKEY_WOW64_32KEYor the 64-bit view withKEY_WOW64_64KEY.It calls
RegKey::open_subkey_with_flagsin thewinregcrate, which itself calls theRegOpenKeyExWfunction.
C:\Users\ek\source\repos\pfdirs [main ≡]> cargo run --target=i686-pc-windows-msvc
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s
Running `target\i686-pc-windows-msvc\debug\pfdirs.exe`
Relevant environment variables:
ProgramFiles C:\Program Files (x86)
ProgramFiles(Arm) [environment variable not found]
ProgramFiles(x86) C:\Program Files (x86)
ProgramW6432 C:\Program Files
Relevant known folders:
FOLDERID_ProgramFiles C:\Program Files (x86)
FOLDERID_ProgramFilesX64 [The system cannot find the file specified. (0x80070002)]
FOLDERID_ProgramFilesX86 C:\Program Files (x86)
FOLDERID_UserProgramFiles C:\Users\ek\AppData\Local\Programs
Relevant CSIDLs:
CSIDL_PROGRAM_FILES C:\Program Files (x86)
CSIDL_PROGRAM_FILESX86 C:\Program Files (x86)
Relevant registry keys - with default view:
ProgramFilesDir C:\Program Files (x86)
ProgramFilesDir (Arm) [The system cannot find the file specified. (os error 2)]
ProgramFilesDir (x86) C:\Program Files (x86)
ProgramW6432Dir C:\Program Files
Relevant registry keys - with KEY_WOW64_32KEY:
ProgramFilesDir C:\Program Files (x86)
ProgramFilesDir (Arm) [The system cannot find the file specified. (os error 2)]
ProgramFilesDir (x86) C:\Program Files (x86)
ProgramW6432Dir C:\Program Files
Relevant registry keys - with KEY_WOW64_64KEY:
ProgramFilesDir C:\Program Files
ProgramFilesDir (Arm) [The system cannot find the file specified. (os error 2)]
ProgramFilesDir (x86) C:\Program Files (x86)
ProgramW6432Dir C:\Program Files
This shows, among other things, that, as documented, the ProgramFilesX64 known folder information is not available to a 32-bit process, even when it is running on a 64-bit system.
PS C:\Users\pickens\repos\pfdirs> cargo run
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s
Running `target\debug\pfdirs.exe`
Relevant environment variables:
ProgramFiles C:\Program Files
ProgramFiles(Arm) C:\Program Files (Arm)
ProgramFiles(x86) C:\Program Files (x86)
ProgramW6432 C:\Program Files
Relevant known folders:
FOLDERID_ProgramFiles C:\Program Files
FOLDERID_ProgramFilesX64 C:\Program Files
FOLDERID_ProgramFilesX86 C:\Program Files (x86)
FOLDERID_UserProgramFiles C:\Users\pickens\AppData\Local\Programs
Relevant CSIDLs:
CSIDL_PROGRAM_FILES C:\Program Files
CSIDL_PROGRAM_FILESX86 C:\Program Files (x86)
Relevant registry keys - with default view:
ProgramFilesDir C:\Program Files
ProgramFilesDir (Arm) C:\Program Files (Arm)
ProgramFilesDir (x86) C:\Program Files (x86)
ProgramW6432Dir C:\Program Files
Relevant registry keys - with KEY_WOW64_32KEY:
ProgramFilesDir C:\Program Files (x86)
ProgramFilesDir (Arm) [The system cannot find the file specified. (os error 2)]
ProgramFilesDir (x86) C:\Program Files (x86)
ProgramW6432Dir C:\Program Files
Relevant registry keys - with KEY_WOW64_64KEY:
ProgramFilesDir C:\Program Files
ProgramFilesDir (Arm) C:\Program Files (Arm)
ProgramFilesDir (x86) C:\Program Files (x86)
ProgramW6432Dir C:\Program Files