Solved

Detecting NT from Delphi 1

Posted on 1998-06-20
3
210 Views
Last Modified: 2010-04-03
How can my Delphi 1 application identify the "windir" while running under Windows NT 4?  IOW, I need to know the directory to which Windows is installed.  I am able to detect this with the following code with Windows 95 and Windows 3.x.  However, for some reason this Delphi 1 routine fails to return the Windows directory if NT 4 is operating system.

var
   WinDirectory : String;

function GetEnvVar( VarName : string ) : string;
var
      Len     : Word;
      EnvStz  : PChar;
      NameStz : array[ 0..180 ] of Char;
begin
      StrPCopy( NameStz, VarName );     { Covert VarName to PChar }
      Len := StrLen( NameStz );
      EnvStz := GetDosEnvironment;      { EnvStz holds entire env }

      while EnvStz^ <> #0 do
      begin                  { Pick off Variable Name and Compare }
        if ( StrLIComp( EnvStz, NameStz, Len ) = 0 ) and
              ( EnvStz[ Len ] = '=' ) then
        begin          { Convert to Pascal string before returing }
             Result := StrPas( EnvStz + Len + 1 );
             Exit;
        end;
        Inc( EnvStz, StrLen( EnvStz ) + 1 );   { Jump to Next Var }
        end;
        Result := '';
end;
...
initialization
      WinDirectory := GetEnvVar('windir');
0
Comment
Question by:Kapusta
[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
3 Comments
 
LVL 10

Accepted Solution

by:
Jacco earned 50 total points
ID: 1354490
Normally you can get the Windows directory using the following API call:

GetWindowsDir (in 16 bit environment)
GetWindowsDirectory (in 32 bit environment)

Windows NT 4 doesn't have the DOS environment settings

Regards Jacco
0
 

Author Comment

by:Kapusta
ID: 1354491
You mean something like this?

procedure TForm1.FormCreate(Sender: TObject);
var
      TheDir : Array[0..64] of char;
      WhereIsWindows : String;
begin
      GetWindowsDirectory(TheDir,144);
      WhereIsWindows := StrPas(TheDir);
      Showmessage(WhereIsWindows);
end;
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1354492
Yep that's the way to go !

Don't know about the exact best way for
StrPas and array of Char but it definitely
should work that way !
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 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