2009年8月24日 星期一

VB Script - Change ODD Drive Letter To 1st Available Drive Letter

1.
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")'Create a filesystem
object
Set Drives = FileSystemObject.Drives 'Create a drives collection

2.
'step through the drive collection, and extract'the drive letter and the type of drive
'according to the Microsoft VBScript documentation
'there are 6 distinct types of drive

For Each DiskDrive in Drives
DriveLetter = DiskDrive.DriveLetterDriveType = DiskDrive.DriveType
Select Case DriveType
Case "0" DriveType = "Unknown type of drive"
Case "1" DriveType = "Removable drive"
Case "2" DriveType = "Fixed drive"
Case "3" DriveType = "Network drive"
Case "4" DriveType = "CD-ROM drive"ODD = DriveLetter
Case "5" DriveType = "RAM Disk"
End Select

'WScript.Echo "Drive " & DriveLetter & " is a " & DriveType
Next
'WScript.Echo "ODD drive letter is " & ODD

3.
' Search the first available drive letter
For i = 67 to 90
strDrive = Chr(i)
If FileSystemObject.DriveExists(strDrive) Then
Else NewODD = strDrive
Exit For
End If

Next
'Wscript.Echo NewODD & " is the new ODD drive letter"

4. call diskpart to change the ODD drive letter

沒有留言: