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