Solved

Find windows directory

Posted on 2002-05-03
8
159 Views
Last Modified: 2010-04-04
I nee some code to find the Windows/WinNT directory.

I tried this one but it's gives me an error :(

function GetWindowsDirectory(lpBuffer: PChar; uSize: UINT): UINT; stdcall;

Function GetWindowsDir:String;
VAR
 Buffer : Array[0..150] OF Char;
Begin
 FillChar(Buffer,SizeOf(Buffer),0);
 GetWindowsDirectory ( Buffer,sizeOf(Buffer));
 Result := StrPas(Buffer );
End;

Anyone else out ther with the good code?

Thanks,
Vincent
0
Comment
Question by:Vincentg
8 Comments
 
LVL 6

Accepted Solution

by:
DrDelphi earned 50 total points
Comment Utility
Straight simple and to the point:




Function WindowsDirectory:string;
var WinDir:array[0..255] of char;
begin
  GetwindowsDirectory(Windir,255);
  Result:=WinDir;
end;



Good luck!!


0
 
LVL 4

Expert Comment

by:nestorua
Comment Utility
HI,
Almost the same as DrDelphi:

function GetWinDir: string;
var lpBuffer: PChar;
       uSize: UINT;
begin
  uSize:=MAX_PATH;
  GetMem(lpBuffer, uSize);
  GetWindowsDirectory(lpBuffer, uSize);
  Result:=String(lpBuffer);
  FreeMem(lpBuffer);
end;

Sincerely,
Nestorua.
0
 
LVL 7

Expert Comment

by:Motaz
Comment Utility
This is my version:

var
  WinDir: PChar;
begin
  WinDir:= StrAlloc(100);
  GetWindowsDirectory(WinDir, 100);
  Label1.Caption:= WinDir;
  StrDispose(WinDir);
end;

btw. No need to declare GetWindowsDirectory header, just make sure that Windows unit is included in uses clause.
Motaz
0
 
LVL 2

Expert Comment

by:dMa
Comment Utility
and this is my version :
(ok it works only on 99% )

'c:\'

heheheheheehehe
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 8

Expert Comment

by:Cesario
Comment Utility
change your code :

Function GetWindowsDir:String;
VAR
  Buffer : Array[0..150] OF Char;
Begin
  FillChar(Buffer,SizeOf(Buffer),0);
  GetWindowsDirectory ( @Buffer,sizeOf(Buffer));
  Result := StrPas(Buffer );
End;

Best Regards

Cesario
0
 
LVL 12

Expert Comment

by:Lee_Nover
Comment Utility
function GetWindowsDir: string;
begin
  SetLength(Result, MAX_PATH{260});
  SetLength(Result, GetWindowsDirectory(PChar(Result), MAX_PATH));
end;

:)
0
 

Author Comment

by:Vincentg
Comment Utility
Thanks a lot :)
All others also many thanks for replying.
0
 
LVL 6

Expert Comment

by:DrDelphi
Comment Utility
Cheers.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now