Solved

Detecting NT from Delphi 1

Posted on 1998-06-20
3
205 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
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert Jpg /PNG To GIF 5 135
How to renew a Delphi rad-studio licence? 5 65
Multiple image collision 13 75
firemonkey keyboard covers the controls 1 25
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 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