Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Windows Directory

0 views
Skip to first unread message

Mark Solesbury

unread,
Sep 4, 2001, 12:48:34 PM9/4/01
to
Help Please.
How can i get delphi to detect the windows installation directory, check for
a file. If its not there then copy a file there??

Eg

if test.dll exist in win dir the do nothing
if not then
copy test.dll to the windows directory

HELP!!!!!!!


Gerwin Philippo

unread,
Sep 4, 2001, 2:26:57 PM9/4/01
to
Function GetWindowsDirectory(lpBuffer: pchar; usize: UINT); UINT;

(From 'Delphi 5 Developer's Guide' by Teixeira and Pacheco):

var
WDir: string;
begin
SetLength(WDir, 144);
If GetWindowsDirectory(pchar(WDir), 144) <> 0 then
begin
SetLength(WDir, StrLen(PChar(WDir)));
ShowMessage(WDir);
End
Else
RaiseLastWin32Error;
End;

"Mark Solesbury" <mark_so...@lineone.net> wrote in message
news:pD7l7.1046$zi3.5...@news2-win.server.ntlworld.com...

AlanGLLoyd

unread,
Sep 4, 2001, 5:11:02 PM9/4/01
to
In article <3b951cf7$0$285$e4fe...@newszilla.xs4all.nl>, "Gerwin Philippo"
<nob...@nowhere.nl> writes:

> SetLength(WDir, 144);
> If GetWindowsDirectory(pchar(WDir), 144) <> 0 then
> begin
> SetLength(WDir, StrLen(PChar(WDir)));
>

MSDN recommends to use MAX_PATH as the length of the initial string,
GetWindowsDirecory returns the actual length of the string. I always use
(ignoring error protection for the example) ...

WinDir : string
WinDirLen : integer;
begin
WinDirLen := MAX_PATH;
SetLength(WinDir, WinDirLen);
WinDirLen := GetWindowsDirectory(PChar(WinDir), WinDirLen);
SetLength(WinDir, WinDirLen);
...

Not that the API returns "C:\" for a root windows directory and "C:\Windows"
for a non-root directory. If you want to cater for a root windows directory
(pretty unlikely) you must handle the different trailing characters.

Alan Lloyd
alang...@aol.com

0 new messages