[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Get "Common files" folder

Posted on 2012-08-20
4
Medium Priority
?
1,212 Views
Last Modified: 2012-08-21
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!
0
Comment
Question by:Stef Merlijn
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
ITugay earned 1000 total points
ID: 38312359
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
 

Author Comment

by:Stef Merlijn
ID: 38312999
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
 
LVL 28

Assisted Solution

by:Sinisa Vuk
Sinisa Vuk earned 1000 total points
ID: 38315022
Win detect if app is 32 bit or 64 bit and use appropriate folder.
0
 

Author Closing Comment

by:Stef Merlijn
ID: 38315203
Thank you very much.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question