Marcelito
asked on
Easy question...
How can I retrieve the Window's Program Folder in Delphi?
ASKER
Sorry, I need 'Programs Files' directory
Sorry again.
Sorry again.
This is not a special windows folder. What do you want to do, exactly?
Cheers,
Raymond.
Cheers,
Raymond.
For win2000 there is a new API called SHGetSpecialPath (I think that was the name) with that you can ask the program files directory.
In the "old" windows versions there is no API that, at least I don't know any... :-(
Regards, Madshi.
In the "old" windows versions there is no API that, at least I don't know any... :-(
Regards, Madshi.
ASKER
My application search for a file, and this search must start in 'Program Files' directory. This directory can be different in each PC.
Hi
ahh but we can do this:
procedure TForm1.Button1Click(Sender : TObject);
var
drive : string;
I : integer;
Rslt: Integer;
SearchRec: TSearchRec;
root : string;
finished : boolean;
begin
finished:= false;
drive := 'ABCDEFGHIJKLMNOPQRSTUVWXY Z'; //maybe take out "A" drive
while not finished do begin
for i := 0 to 24 do begin
root := drive[i]+':';
if Root[Length(Root)] = '\' then Root := Root + '*.*'
else Root := Root + '\*.*';
Rslt := FindFirst(Root, faDirectory, SearchRec);
if Rslt = 0 then
begin
while Rslt = 0 do
begin
if (SearchRec.Attr and faDirectory) <> 0 then
begin
if Pos('Program Files',searchrec.Name) <> 0
then begin
ShowMessage(drive[i]+':\'+ SearchRec. Name); //have path here
finished := true;
end;
end;
Rslt := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
end;
end;
end;
Regards Barry :-)
ahh but we can do this:
procedure TForm1.Button1Click(Sender
var
drive : string;
I : integer;
Rslt: Integer;
SearchRec: TSearchRec;
root : string;
finished : boolean;
begin
finished:= false;
drive := 'ABCDEFGHIJKLMNOPQRSTUVWXY
while not finished do begin
for i := 0 to 24 do begin
root := drive[i]+':';
if Root[Length(Root)] = '\' then Root := Root + '*.*'
else Root := Root + '\*.*';
Rslt := FindFirst(Root, faDirectory, SearchRec);
if Rslt = 0 then
begin
while Rslt = 0 do
begin
if (SearchRec.Attr and faDirectory) <> 0 then
begin
if Pos('Program Files',searchrec.Name) <> 0
then begin
ShowMessage(drive[i]+':\'+
finished := true;
end;
end;
Rslt := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
end;
end;
end;
Regards Barry :-)
ASKER
Sorry, but if I install Windows in englis, the directory is 'Programs Files' and if I install in Spanish is 'Archivos de Programa', etc...
I need a function like GetWindowsDirectory or GetWindowsSystemDirectory. ..
I need a function like GetWindowsDirectory or GetWindowsSystemDirectory.
Program Files is not a special directory. So far as I know it is not even on the path by default, which means you will have to look for it yourself. Barry's suggestion is probably the best you are going to see. I'd only suggest that if you know that you are distributing to different countries with other languages, you make allowances in your code.
Good luck!!
Good luck!!
ok the last way i think of:
note there are 2 reg keys where you can read this.
uses Registry;
procedure TForm1.Button1Click(Sender : TObject);
var
R: Tregistry;
begin
R :=TRegistry.Create;
R.Rootkey:=HKEY_LOCAL_MACH INE;
with R do try
CreateKey('\Software\Micro soft\Windo ws\Current Version\') ;
OpenKey('\Software\Microso ft\Windows \CurrentVe rsion\', True);
Edit1.Text := ReadString('ProgramFilesDi r');
Edit2.Text := ReadString('ProgramFilesPa th');
R.CloseKey;
finally
R.Free;
end;
end;
this should return path in corrct language.
note there are 2 reg keys where you can read this.
uses Registry;
procedure TForm1.Button1Click(Sender
var
R: Tregistry;
begin
R :=TRegistry.Create;
R.Rootkey:=HKEY_LOCAL_MACH
with R do try
CreateKey('\Software\Micro
OpenKey('\Software\Microso
Edit1.Text := ReadString('ProgramFilesDi
Edit2.Text := ReadString('ProgramFilesPa
R.CloseKey;
finally
R.Free;
end;
end;
this should return path in corrct language.
Hi,
go to the http://www.torry.ru -> Components Page -> Files & Drives #2 -> TGetFoler (by haehnen ;c))
I think this component will help you
bye
go to the http://www.torry.ru -> Components Page -> Files & Drives #2 -> TGetFoler (by haehnen ;c))
I think this component will help you
bye
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanx, Barry, for the tip... :-)
err, GetWindowsDirectory(lpBuff er, 255); should that not automaticly just do it, regardless of what language it is is in...
Craig C.
Craig C.
oops, got a bit of a stutter there :)
procedure TForm1.Button1Click(Sender
var
lpBuffer: array[0..255] of char;
SysDir: string;
begin
GetWindowsDirectory(lpBuff
SysDir := lpBuffer;
Label1.Caption := sysdir;
end;
Regards Barry