Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Detecting NT from Delphi 1

Posted on 1998-06-20
3
Medium Priority
?
222 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 150 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

705 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