Solved

Detecting NT from Delphi 1

Posted on 1998-06-20
3
214 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

617 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