Solved

Detect path to WINDOWS directory ?

Posted on 1997-06-02
8
384 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 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

18 Experts available now in Live!

Get 1:1 Help Now