Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' "Drive Letter To Desired.vbs"
- ' The Volume Name must end with characters @X where the "X" is the Desired Drive Letter.
- ' Does not run on: Win2000, WinXP
- Set SystemSet = GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")
- For each System in SystemSet
- Next
- Dim WshShell, FSO
- Set WshShell = WScript.CreateObject("WScript.Shell")
- Set FSO = CreateObject("Scripting.FileSystemObject")
- thisDrive = Left(WScript.ScriptFullName, 1) & ":"
- Set d = FSO.GetDrive(FSO.GetDriveName(FSO.GetAbsolutepathname(thisDrive)))
- If(Left(Right(d.VolumeName,2),1))="@" Then
- desiredDrive = Right(d.VolumeName,1) & ":"
- Else
- MsgBox "The Desired Drive Letter is Not Specified." & Chr(13) & Chr(13) & "No Actions Taken." , vbOKOnly, WScript.ScriptFullName
- wscript.quit
- End If
- If (thisDrive = desiredDrive) Then
- MsgBox "This Volume is Already Mounted as " & desiredDrive & " drive." & Chr(13) & Chr(13) & "No Actions Taken." , vbOKOnly, WScript.ScriptFullName
- wscript.quit
- End If
- If (FSO.FolderExists(desiredDrive)) Then
- MsgBox "The drive letter " & desiredDrive & ": is in Use by Another Volume." & Chr(13) & Chr(13) & "No Actions Taken." , vbOKOnly, WScript.ScriptFullName
- wscript.quit
- End If
- ' Get volume associated to the current drive letter.
- '
- Set objExec = WshShell.Exec("mountvol " & thisDrive & " /L")
- strVolume = Trim(objExec.StdOut.ReadLine())
- while objExec.Status = 0
- WScript.Sleep(100)
- Wend
- ' Unmount the drive.
- '
- Set objExec = WshShell.Exec("mountvol " & thisDrive & " /D")
- while objExec.Status = 0
- WScript.Sleep(100)
- Wend
- ' Mount the drive with the desired drive letter.
- '
- Set objExec = WshShell.Exec("mountvol " & desiredDrive & " " & strVolume)
- while objExec.Status = 0
- WScript.Sleep(100)
- Wend
- 'If OS is W7, W8 or W10 then open the Windows Explorer again
- 'because the above closes it.
- If InStr(osCaption, "Windows 7") Then
- WshShell.Run "explorer.exe" & " /e, " & desiredDrive
- ElseIf InStr(osCaption, "Windows 8") Then
- WshShell.Run "explorer.exe" & " /e, " & desiredDrive
- ElseIf InStr(osCaption, "Windows 10") Then
- WshShell.Run "explorer.exe" & " /e, " & desiredDrive
- End If
- Set FSO=nothing
- Set WshShell=nothing
- wscript.quit
Advertisement
Add Comment
Please, Sign In to add comment