6

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?

7

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

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

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

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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