Get "Common files" folder

Hi,

How can supply me with a function that will return the common files-folder on a system.
If Windows OS is 32bit, it should return: <drive>:\Program Files\Common Files\
If Windows OS is 64bit, it should return: <drive>:\Program Files (x86)\Common Files\
It should work on Window XP, Vista, 7 and 8.

Thanks!
Stef MerlijnDeveloperAsked:
Who is Participating?
 
ITugayConnect With a Mentor Commented:
Here is it.

uses
  ...
  ShlObj;

...

const
   CSIDL_PROGRAM_FILES_COMMON = $2B;

function GetSpecialPath(CSIDL: word): string;
var
  S:  string;
begin
  SetLength(S, MAX_PATH);
  if not SHGetSpecialFolderPath(0, PChar(S), CSIDL, true) then
    Result := ''
  else
    Result := PChar(S);
end;

procedure TForm4.SpeedButton1Click(Sender: TObject);
begin
  Caption := GetSpecialPath(CSIDL_PROGRAM_FILES_COMMON);
end;

Open in new window

0
 
Stef MerlijnDeveloperAuthor Commented:
Can you explain how it does take into account if it is a 64bit or 32bit system in order to get the right folder (x86 or not)?
0
 
Sinisa VukConnect With a Mentor Commented:
Win detect if app is 32 bit or 64 bit and use appropriate folder.
0
 
Stef MerlijnDeveloperAuthor Commented:
Thank you very much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.