Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Quickest way to locate System32 Dir?

by Anonymous Monk
on Jan 14, 2004 at 19:58 UTC ( #321342=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've been looking at thw Win32 modules for a fast solution to determine the absolute path to the System32 directory on different versions of Windows. I've also looked at using the File::Find module but this has proven to be very slow using the following code:
find(\&locate_system32, "C:\\"); # Not to mention it only looks on one drive (i.e. "C") sub locate_system32 { if (/system32/) { $system32 = "$File::Find::dir"; } }

Does anyone have any suggestions?


Replies are listed 'Best First'.
Re: Quickest way to locate System32 Dir?
by Coruscate (Sexton) on Jan 14, 2004 at 20:36 UTC

    #!c:/perl/bin/perl -w $|++; use strict; use Win32::API; Win32::API->Import('kernel32', 'GetSystemDirectoryA', 'PN', 'N'); my $systemdir = ' ' x 100; my $len = GetSystemDirectoryA($systemdir, 100); substr($systemdir, $len) = ""; print "System directory found at: '$systemdir'\n";

Re: Quickest way to locate System32 Dir?
by PodMaster (Abbot) on Jan 14, 2004 at 20:07 UTC
    Don't do that.
    perl -le"die $ENV{WINDIR}" E:\WINNT at -e line 1.
    perl -le"die $ENV{SYSTEMROOT}" E:\WINNT at -e line 1.
    update: I don't know what you are talking about l3nz, WINDIR is my first suggestion, and I'm not using either.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Why don't you use WINDIR? it's the standard magic variable windows uses when creating a link, for instance.
Re: Quickest way to locate System32 Dir?
by MADuran (Beadle) on Jan 14, 2004 at 20:17 UTC
    System32 directory is almost always in the System root directory. In windows NT/2000/XP/2003 the path to the system32 is always SystemRoot\system32, where SystemRoot is in the ENV hash. When I run this:
    C:\>perl -e "@keys = keys(%ENV); foreach $key (@keys){print qq/$key = $ENV{$key} \n/;};"

    I show SYSTEMROOT such:

    I cannot be sure if this is true on Win9x systems (I believe it is).

    update: grammar repair.

    In need of a spiffy sig

Re: Quickest way to locate System32 Dir?
by flyingmoose (Priest) on Jan 14, 2004 at 21:01 UTC
      flyingmoose .. you need to establish the value by setting

      use constant CSIDL_SYSTEM => 0x25; # Decimal 37

      before you can GetFolderPath.
      In any case, that is the exact equivalent of calling 'GetSystemDirectory()' .

      "When you are faced with a dilemma, might as well make dilemmanade. "
        Actually, no. You only need to import it:
        use Win32 qw(CSIDL_SYSTEM); print Win32::GetFolderPath(CSIDL_SYSTEM);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://321342]
Approved by calin
Front-paged by BrowserUk
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2018-07-18 06:24 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (383 votes). Check out past polls.