RE: what is the most robust and accurate way to determine the BOOTvolume?

2009-03-31 Thread Brian Raven
From: perl-win32-users-boun...@listserv.activestate.com
[mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of
Greg Aiken
Sent: 30 March 2009 23:01
To: perl-win32-users@listserv.activestate.com
Subject: RE: what is the most robust and accurate way to determine the
BOOTvolume?

> I discovered (on my computer) that ENV vars named 'SystemRoot' and
'SystemDrive' exist.
> 
> Does anyone know if these would be present on all Windows computers?  
> 
> If so, it would seem the answer here would be to merely look at
$ENV{'SystemDrive'}
> 
> Can anyone think of a reason where these ENV vars would not exist?

First, do you mean boot volume or system volume. They are often the
same, but not necessarily. See http://support.microsoft.com/kb/314470.

Second, if you really mean 'robust and accurate' you should be careful
of relying on environment variables, as they can be easily changed or
removed. It might be safer to use a win32 API call. For example (and
this is the fiest time I have tried this):

use strict;
use warnings;

use Win32::API;

my $proto = 'UINT GetSystemDirectory(LPTSTR lpBuffer, UINT uSize)';
Win32::API->Import('kernel32', $proto)
or die "Failed to import $proto: $^E\n";
my $buflen = 20;
my $buf = ' ' x $buflen;
my $result = GetSystemDirectory($buf, $buflen);
if ($result == 0) {
die "GetSystemDirectory failed: $^E\n";
}
elsif ($result > $buflen) {
die "GetSystemDirectory buffer needs to be at least $result
bytes\n";
}

print "System directory is ", substr($buf, 0, $result), "\n";

HTH

-- 
Brian Raven 

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy.
Any unauthorised copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: what is the most robust and accurate way to determine the BOOTvolume?

2009-03-31 Thread Chris Wagner
Hi.  The "right way" to retrieve this kind of information is from WMI.  If u
never used it download Scriptomatic from Microsoft and start exploring.  I
don't think it flat out tells u the information ur looking for but I think u
can figure it out by cross referencing some things.  The branches u'll
probably be interested in are Win32_OperatingSystem, Win32_LogicalDisk*, and
Win32_Disk*.  But be careful to differentiate between the system device and
the boot device.  They're not necessarily the same thing and u can get
burned by Microsoft's obtuse terminology and numbering system.  For example
on my system, what boot.ini calls disk 0 part 1, is really disk 1 part 0.
Some branches use the latter numbering, others the former. *shakes fist*


At 03:00 PM 3/30/2009 -0700, gai...@visioninfosoft.com wrote:
>I discovered (on my computer) that ENV vars named 'SystemRoot' and
>'SystemDrive' exist.
>
> 
>
>Does anyone know if these would be present on all Windows computers?  
>
> 
>
>If so, it would seem the answer here would be to merely look at
>$ENV{'SystemDrive'}
>
> 
>
>Can anyone think of a reason where these ENV vars would not exist?
>
> 


--
REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=--
"...ne cede malis"

0100

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs