31

Program Files is typically C:\Program Files; however it is not always; famously on German installs it was C:\Programme, the installation drive was not guaranteed to be C, and other things would make hardcoding "Program Files" fraught with peril.

The modern suggestion is SHGetFolderPath which didn't exist on Windows 95. A little spelunking revealed SHGetSpecialFolderLocation but that doesn't actually work.

 SHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidprogramfiles))

Yields an error. A trace bit of documentation left around on MSDN says CSIDL_PROGRAM_FILES started existing with Version 5 (Windows 2000). So how the hey were installers supposed to find it?

I can make this work by reading HKLM Software\Microsoft\Windows\CurrentVersion ProgramFilesDir ; however this reading the registry for this stuff is something Raymond Chen has been rather famously yelling about.

7
  • Not an answer, but from memory, if you used an installer such as InstallShield, then there was some installer syntax for all of the usual installation target directories. That might just be passing the buck: how does InstallShield know? My experience was mostly NT, but I think the installler mechanisms were similar.
    – dave
    Commented Mar 16, 2022 at 2:27
  • 3
    There's always %ProgramFiles% (etc) in modern Windows; I forget when that might have shown up.
    – dave
    Commented Mar 16, 2022 at 2:35
  • 2
    @another-dave: Not Windows 95 (it had to keep its environment small because DOS is still active). %ProgramFiles% is from the NT branch.
    – Joshua
    Commented Mar 16, 2022 at 2:56
  • Also not an answer, but installing Internet Explorer 5 on Windows 95 should update the shell DLLs to version 5 (with support for CSIDL_PROGRAM_FILES). Commented Mar 16, 2022 at 6:22
  • 4
    "Raymond Chen has been famously yelling about" - What he says, is "you should use SHGetFolderPath()". But when that isn't reliably present (because no one bothered to install IE5.0), it's pretty hard to follow that advice....
    – tofro
    Commented Mar 16, 2022 at 10:54

3 Answers 3

36

According to Microsoft KB Q178625, for Windows 95

developers should refer to the system registry to identify the location of the Program Files directory.

It goes on to suggest that

However, to ensure that your application can run on any platform, it can check the registry value for the location of a directory. This approach eliminates the need to hard code the directory path. Refer to the value for the ProgramFilesDir key at [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion] to find the localized name of the Program Files directory.

35

Some (quite a lot) simply didn't. A clear indication of this: Typical fresh Spanish or German installations started with a "C:\Programme" or "C:\Archivos de Programmas" folder, and after installing some programs, ended up having a "C:\Program Files" folder as well (i.e. the installation path was hard-coded into the installer of some programs.)

For early Windows 95 installations, I believe there is no simple way other than reading the

  $HKLM Software\Microsoft\Windows\CurrentVersion ProgramFilesDir 

registry key.

16
  • 5
    ...and I can confirm that said registry key is visible in a screenshot on page 1029 of the Windows 95 Resource Kit... so it should be there from the earliest releases.
    – ssokolow
    Commented Mar 16, 2022 at 10:28
  • 3
    I've also seen German software install into C:\Programme on English Windows (repeatedly, and as late as XP), and even something with a typo hardcoded - C:\Programm Files I think. The latter was something minor but the former was commercial
    – Chris H
    Commented Mar 16, 2022 at 11:43
  • 7
    There was no simple way except for this very simple way.....love it. Commented Mar 16, 2022 at 12:37
  • 10
    Even in the days of Windows XP, when I accidentally ended up installing the entire OS in D:\ (yes, D:\Windows, D:\Program Files, the whole thing), there would still be programs which kept creating the directory in C:\...'
    – grawity
    Commented Mar 16, 2022 at 17:21
  • 9
    Yes it was pretty common for programs to ignore the convention and not install in \Program Files for quite some time after Win 95 was released. In fact even around 2007 I still remember many of the "enterprise" applications we used installed off the root by default - often it seemed because they didn't properly handle long file/folder names and/or folders with spaces in them properly). Commented Mar 17, 2022 at 1:09
5

At this time, it was common to be forced to implement a cascade of tests to check some system elements, from the "best one" to the "worst one", and we were often forced to even add a "random guess shot" when everything failed! Obviously, the first answer causes a flow break and you'll return the best possible reply each time.

For history purpose, check how you determine which kind of executable a .EXE is (DOS, DOS/Extended, Win16, Win32, ...), and you'll see exactly which kind of tricky analysis is required for these old system "functionalities".

For your particular need, you'll need to check, in this order:

  1. ShellAPI: reliable when present, but it was dependent on IE to be there.
  2. Registry: Near reliable, at least on Win95.
  3. Hard drive scan: you'll search things known as installed to see where they are (for example, CommonFiles stuff...).
  4. Known file names: get the operating system language, use a LUT/map to get the associated name of Program Files.
  5. Ask the user OR use a hardcoded value (get system drive, append \Program Files and hope that it will suits).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .