Jump to content

DriveLetter Variables


 Share

Recommended Posts

Since I wrote DetectCD.exe I have had requests for a similar utility for removable drives. So I rewrote & renamed DetectCD to DetectDrive.

It Now Detects all drive attached to a system (except A:) and creates a permanent environment variable.

Usage: DetectDrive {options}

Options:

HELP Shows help this screen

BACKSLASH Return value has backslash 'C:\', default is no backslash 'C:'

REMOVABLE Create variable for all removable drives except A:, i.e usb, firewire, etc. REMOVABLE#

FIXED Create variable for all fixed disk drives, FIXED#

REMOTE Create Variable for all Remote or network drives, REMOTE#

CDROM Create Variable for all CD-Rom drives, CDROM#

RAMDISK Create Variable for all RamDrives, RAMDRIVE#

ALL All variables will be created

# will be replaced with a number corresponding to the order in which the drive is lettered starting with 1 for each group.

DetectDrive Fixed CDROM Removable Backslash

returns the following on my system in the environment variables

FIXED1=C:\ 
FIXED2=D:\
FIXED3=F:\
CDROM1=E:\
CDROM2=M:\
REMOVEABLE1=G:\

You can use as many switches as desired.

But at least one must be selected other than BACKSLASH

EDIT: IMPORTANT NOTE: 4/7/2006

You will not see the variables created until you open a new cmd window, but if you go to 'System Properties -> advanced -> environment variables' they should be listed there.

Since the variables are directly written to the registry they are not available to the calling CMD script.

DetectDrive.exe

Link to comment
Share on other sites


  • 1 month later...

In short, NO. This program queries windows for the drive mappoints and then creates the environment variables.

I don't know of a way to differentiate between drive tyes in DOS if someone knows a way I'd be glad to rewrite or assist in creating a dos version.

Link to comment
Share on other sites

you will not see the variables created until you open a new cmd window, but if you go to 'System Properties -> advanced -> environment variables' they should be listed there.

Since the variables are directly written to the registry they are not available to the calling CMD script.

Link to comment
Share on other sites

Yes, ok, from a new command prompt they work in win2k too.

But (as you said) they are persistent, so that if I issue the

DETECTDRIVE ALL

command with a Removable drive attached, then I re-boot without it, the

REMOVABLE1=K:

is still there (and I have to reset it manually).

Same things obviously happen with the (fixed as seen by Windows) drive which is actually removable as it is in a removable tray, when I reboot without it and rerun the utility the drive is still there.

Still have to try how it behaves when called from a batch file.

All in all (don't take it as a critic, it is just a suggestion) I would prefer a non-persistent option, so that I don't have to reset all variables via batch.

Another feature (I know I am asking a lot) could be to make the variable as a comma separated list, something like:

FIXED=C:,D:,E:

CDROM=F:,G:,H:

REMOVABLE=K:

So that the variable has not a progressive number.

I already wrote a small batch that detects fixed and CD drives, if it is not a "secret of the trade" could you let me know how you detect the removable ones?

Thanks,

jaclaz

Link to comment
Share on other sites

I will work on the comma delimited list, shouldn't be too dificult once I find where I left the source code.

As to removing the variables i can add a REMOVE switch which would parse the environment variables and remove all of the variables which it may have created. I won't say that it created because someone may create there own CDROM22 and it would be removed. I do not want to leave a log behind in the registry or a file.

I could also make a REFRESH which would do the above and then create all new variables.

Or a VERIFY which would check each variable and verify it was the right type and letter.

Or maybe REMOVEMISSING to remove variables which no longer have properly associated drives.

Asfar as the secret to determine drivetype I use to the DriveType Constants and Property of VB6. These are also available in vbscript as I recall.

Unknown 0 Drive type can't be determined.

Removable 1 Drive has removable media. This includes all floppy drives and many other varieties of storage devices.

Fixed 2 Drive has fixed (nonremovable) media. This includes all hard drives, including hard drives that are removable.

Remote 3 Network drives. This includes drives shared anywhere on a network.

CDROM 4 Drive is a CD-ROM. No distinction is made between read-only and read/write CD-ROM drives.

RAMDisk 5 Drive is a block of Random Access Memory (RAM) on the local computer that behaves like a disk drive.

Link to comment
Share on other sites

As far as the secret to determine drivetype I use to the DriveType Constants and Property of VB6. These are also available in vbscript as I recall.

Thanks, IcemanD, I'll look into the VB specifications.

About the problem of an user creating a CDROM22 variable, you could "personalize" the varianle names, such as:

ICEMFIXED

ICEMCDROM

ICEMREMOVABLE

this way it is unlikely that an user will make these variables.

Cheers,

jaclaz

Link to comment
Share on other sites

I'm trying it under win2k, and it's doing nothing, either with the win2k or winxp version of the msvbvm60.dll.

It does not set the variables under either 4nt or cmd.

If i recall correctly, you can't set environment variables from an exe, only a batch. So what most people usually do under OS/2 or windows is to pass the output to a batch file, and then call the batch file.

This would be quite handy under bartpe, because the environment changes in the registry is not passed through to started to later shells. You have to use something like nu2menumsg.exe to change the real-mode environment.

Calling a batch file, eg setdrive.cmd, would allow you to query once and set in many sessions, eg detectdrive all > %temp%\drives.cmd, and then call drives.cmd whenever you want to find out who's where.

W

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...