Solved

Detecting NT from Delphi 1

Posted on 1998-06-20
3
199 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
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
Jacco earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

10 Experts available now in Live!

Get 1:1 Help Now