Recent Changes - Search:



My journals will take the place of a blog. They have moved to

Sites I take responsibility for






Places I frequent



Items for sale:


edit SideBar

Determine the system drive

Include our styles below Infobox - invoke as >>infobox<< ... >><<

Codebox: - invoke as >>codebox<< ... >><<

warnbox: - invoke as >>codebox<< ... >><<

editingbox: - invoke as >>codebox<< ... >><<

noticebox: - invoke as >>codebox<< ... >><<

Page bread crumbs:

Pages by tags: (:listtags:)
Subscribe to this wiki: RSS Feed RSS or subscribe to this page for changes: RSS Feed RSS
496 articles have been published so far. Recent changes
(:addThis btn="custom":)

First Definitions for system volume and boot volume

On a Windows system at the command prompt

if you type in the command SET this will display a list of environment variables available on the system and also accessible in Win32 Perl via $ENV{''}

  == $ENV{'SystemDrive'}
  == $ENV{'SystemRoot'}

This is standard across windows platform (now I cant confirm this for Windows 95,98, me)

In Perl/Win32:

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 first 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

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

The "right way" to retrieve this kind of information is from WMI. If you never used it download Scriptomatic from Microsoft and start exploring. I don't think it flat out tells you the information you are looking for but I think you can figure it out by cross referencing some things. The branches you will 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 you 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*

Kevin's Public Wiki maintained and created by Kevin P. Inscoe is licensed under a
Creative Commons Attribution 3.0 United States License.

Back to my web site -

Edit - History - Print - Recent Changes - Search
Page last modified on April 10, 2012, at 11:18 AM EST