Solved

Detect path to WINDOWS directory ?

Posted on 1997-06-02
8
387 Views
Last Modified: 2010-04-06
How can I detect the path to WINDOWS directory ?
I need to know the complete path to the directory where windows is installed.
0
Comment
Question by:sile
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 4

Expert Comment

by:StevenB
ID: 1336746
There is a component available from, amongst others, this site:

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.
0
 
LVL 1

Expert Comment

by:ozzy
ID: 1336747
Use the variable WINDIR in your program.  It contains the path to windows.
0
 

Author Comment

by:sile
ID: 1336748
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 ?
0
 
LVL 1

Expert Comment

by:sleach
ID: 1336749
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;

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Accepted Solution

by:
alona041797 earned 30 total points
ID: 1336750
You should better use GetWindowsSystemDirectory because on some systems the directory isn't WinDir\system.

Instead of result:=string(buff) you should use StrPCopy (or is it called StrPCpy) that creates Pascal-style strings from PChars.

0
 
LVL 1

Expert Comment

by:ozzy
ID: 1336751
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
0
 

Author Comment

by:sile
ID: 1336752
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 ?
0
 
LVL 1

Expert Comment

by:sleach
ID: 1336753
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;

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

27 Experts available now in Live!

Get 1:1 Help Now