sile
asked on
Detect path to WINDOWS directory ?
How can I detect the path to WINDOWS directory ?
I need to know the complete path to the directory where windows is installed.
I need to know the complete path to the directory where windows is installed.
Use the variable WINDIR in your program. It contains the path to windows.
ASKER
I can't get it to work. It's a Pchar type of variable, isn't it ?
I'm using this code to detect if there is a file in WINDOWS\SYSTEM directory:
if FileExists(WINDIR + '\System\' + 'nviewlib.dll')=false then...
I declared the WINDIR variable as PChar.
The program reports no errors but can not find the file that is there.
Is there something I have to add to USES clause ?
How can I get it to work ?
I'm using this code to detect if there is a file in WINDOWS\SYSTEM directory:
if FileExists(WINDIR + '\System\' + 'nviewlib.dll')=false then...
I declared the WINDIR variable as PChar.
The program reports no errors but can not find the file that is there.
Is there something I have to add to USES clause ?
How can I get it to work ?
I can't get ozzy's answer to work either. However, this simple function will DEFINITELY work. If you like it, reject ozzy's answer, and i'll repost it as an answer.
function WinDir: string;
var
buff: array[0..255] of char;
WindowsDir: string;
begin
GetWindowsDirectory(buff, sizeof(buff));
result := string(buff); {Convert to String}
end;
function WinDir: string;
var
buff: array[0..255] of char;
WindowsDir: string;
begin
GetWindowsDirectory(buff, sizeof(buff));
result := string(buff); {Convert to String}
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, you are right that my answer was in error.
I appologize for the inconvienence. I read that WINDIR stores the windows directory in it, but the place I read that was in error.
whoops, sorry
I appologize for the inconvienence. I read that WINDIR stores the windows directory in it, but the place I read that was in error.
whoops, sorry
ASKER
How about some code on that alona ? By the way the call is Get SystemDirectory ,but something isn't working right .
I need to find a file in system directory and if it's not there to copy it there. Somehow nothing seems to work. Could you help ?
I need to find a file in system directory and if it's not there to copy it there. Somehow nothing seems to work. Could you help ?
sile, try this code. It will fetch the Windows System directory, and assign it to SystemDir. Hope this helps.
var
buff: array[0..255] of char;
SystemDir: string;
begin
GetSystemDirectory(buff, sizeof(buff));
SystemDir := string(buff); {Convert to String}
end;
var
buff: array[0..255] of char;
SystemDir: string;
begin
GetSystemDirectory(buff, sizeof(buff));
SystemDir := string(buff); {Convert to String}
end;
http://www.worldnet.net/~cycocrew/delphi/components.html
called TFileFind, which should provide the help you need. Either use the component wholesale, or examine the source code to write your own.
Steven.