Solved

Detect path to WINDOWS directory ?

Posted on 1997-06-02
8
390 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 54
DBGrid or StringGrid ? 6 89
How to load 2 images in same column in Delphi 2 47
Wincontrol not (correctly) drawn 15 38
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

772 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