Solved

Detect path to WINDOWS directory ?

Posted on 1997-06-02
8
396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 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