Solved

Detect path to WINDOWS directory ?

Posted on 1997-06-02
8
392 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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