Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

On windows XP/7, is there a way to identify from a script (never mind the script language being used) that a disk is not a network or fixed drive?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

This VBS script will do it:

dim filesys
set filesys = CreateObject("Scripting.FileSystemObject") 
Set drv = filesys.GetDrive("C")
 select case drv.DriveType 
   case 0: drtype = "Unknown" 
   case 1: drtype = "Removable" 
   case 2: drtype = "Fixed" 
   case 3: drtype = "Network" 
   case 4: drtype = "CD-ROM" 
   case 5: drtype = "RAM Disk"  
end select
 MsgBox "The specified drive is a " & drtype & " type disk."

Reference - DevGuru

share|improve this answer
    
+1 for a concise and useful little piece of code. Sticking this in my code library. –  TristaanOgre Jun 20 '11 at 14:53

Here's how you might do this using WinTask and the Win32 API GetDriveTypeA.

'
' GetDriveType
'
' Author: Joe Strazzere
'

dim a as unsigned    
dr$ = inputbox$("Enter the drive","GetDriveType","C:")    
a   = External("kernel32","GetDriveTypeA",dr$)

Select Case a

case 1    
  msgbox("Drive "+dr$+" was not found!",0,"GetDriveType")

case 2    
  msgbox("Drive "+dr$+" is a removable drive",0,"GetDriveType")

case 3    
  msgbox("Drive "+dr$+" is a fixed drive",0,"GetDriveType")

case 4    
  msgbox("Drive "+dr$+" is a network drive",0,"GetDriveType")

case 5    
  msgbox("Drive "+dr$+" is a CD-ROM drive",0,"GetDriveType")

case 6    
  msgbox("Drive "+dr$+" is a RAM drive",0,"GetDriveType")

case else    
  msgbox("I just don't know!",0,"GetDriveType")

endselect

http://strazzere.blogspot.com/2005/01/wintask-getdrivetype.html

share|improve this answer
    
Thanks for the formatting help, Jeff. –  Joe Strazzere Jun 21 '11 at 11:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.