X
x38class
Guest
vbscript to change drive letter
I need to change a drive letter (M to H), for my purposes I have modified the code in the above link as follows, however there are errors which I do not know how to resolve, they are:
1. how do I assign wscript: 2. how do I assign objWMIService: 3. how do I assign colVolumes = objWMIservice.ExecQuery
Thanks for any assistance, also, if run as restricted user will it execute?
'This works on Windows 10
' Elevate the script to run As Administrator
If Not WScript.Arguments.Named.Exists("elevate") Then
CreateObject("Shell.Application").ShellExecute(WScript.FullName _
, """" & WScript.ScriptFullName & """ /elevate", "", "runas", 1)
WScript.Quit()
End If
objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
colVolumes = objWMIService.ExecQuery _
("Select * from Win32_Volume Where Name = '" & "M" & ":\\'")
For Each objVolume In colVolumes
objVolume.DriveLetter = "H" & ":"
objVolume.Put_()
Next
Continue reading...
I need to change a drive letter (M to H), for my purposes I have modified the code in the above link as follows, however there are errors which I do not know how to resolve, they are:
1. how do I assign wscript: 2. how do I assign objWMIService: 3. how do I assign colVolumes = objWMIservice.ExecQuery
Thanks for any assistance, also, if run as restricted user will it execute?
'This works on Windows 10
' Elevate the script to run As Administrator
If Not WScript.Arguments.Named.Exists("elevate") Then
CreateObject("Shell.Application").ShellExecute(WScript.FullName _
, """" & WScript.ScriptFullName & """ /elevate", "", "runas", 1)
WScript.Quit()
End If
objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
colVolumes = objWMIService.ExecQuery _
("Select * from Win32_Volume Where Name = '" & "M" & ":\\'")
For Each objVolume In colVolumes
objVolume.DriveLetter = "H" & ":"
objVolume.Put_()
Next
Continue reading...