Recent Changes - Search:


Code:


Social:


My journals will take the place of a blog. If you go to the Journal page there is an RSS feed to subscribe with.

« November 2017 
SunMonTueWedThuFriSat
   1234
567891011
12131415161718
19202122232425
2627282930  

Sites I take responsibility for

West Volusia, Florida

Documents

Technical

General

Me

Living

Places I frequent

Hobbies

Humor

Items for sale:


Clipboard

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: Welcome to ke3vin.org! - My Public Technical Notes - Software And Operating Systems - Microsoft Windows - HOWTOS - Determine The System Drive

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
Share

2016-03-22: This site is being moved to my main site at https://kevininscoe.com/wiki as part of a consolidation to one domain.


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
bytes\n";
}

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 - http://kevininscoe.com

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