strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objDictionary = CreateObject("Scripting.Dictionary")
Set Shell = WScript.CreateObject("WScript.Shell")
Set WinDir = objFileSystem.GetSpecialFolder(WindowsFolder)
Set colDisks = objWMIService.ExecQuery ("Select * From Win32_LogicalDisk")
Set colVols = objWMIService.ExecQuery ("Select * From Win32_Volume")
dir = Shell.CurrentDirectory
isMounted = 0
For Each objDisk in colDisks
objDictionary.Add objDisk.DeviceID, objDisk.DeviceID
Next
'Check if SystemVolume is already mounted
For Each objVol in colVols
If objVol.SystemVolume = True then
If objDictionary.Exists(objVol.DriveLetter) Then
TargetDrive = objVol.DriveLetter
isMounted = 1
Wscript.Echo("SystemVolume is: " & TargetDrive)
Exit For
End If
End If
Next
'find a free drive letter
If isMounted = 0 Then
For a = 67 to 90
TargetDrive = Chr(a) & ":"
If objDictionary.Exists(TargetDrive) Then
Else
Wscript.Echo(TargetDrive & " is the next available drive letter.")
Exit For
End If
Next
End If
'mount SystemVolume
If isMounted = 0 Then
For Each objVol in colVols
If objVol.SystemVolume = True then
Wscript.Echo("mounting: " & TargetDrive)
objvol.DriveLetter = TargetDrive
objVol.Put_
End If
Exit For
Next
End If