123456789101112131415161718192021222324252627282930313233343536 |
- Option Explicit
- Dim objNetwork, objShell
- Dim strDriveLetter, strNetworkPath
- Dim colDrives, intDrive, strDrives
- If WScript.Arguments.length =0 Then
- Set objNetwork = CreateObject("WScript.Network")
- Set colDrives = objNetwork.EnumNetworkDrives
- For intDrive = 0 To (colDrives.Count -1) Step 2
- ' WScript.Echo colDrives.Item(intDrive) & " is mapped to: " & colDrives.Item(intDrive + 1)
- If Len(strDrives) > 0 Then strDrives = strDrives & " "
- strDrives = strDrives & " " & Chr(34) & colDrives.Item(intDrive) & Chr(34) & " " & Chr(34) & colDrives.Item(intDrive + 1) & Chr(34)
- Next
- If Len(strDrives) > 0 Then
- ' re-call script with elevation
- Set objShell = CreateObject("Shell.Application")
- objShell.ShellExecute "cscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & strDrives, "", "runas", 1
- Else
- WScript.Echo "No drives Mapped."
- End If
- Else
- ' elevated part
- Set objNetwork = CreateObject("WScript.Network")
- For intDrive = 0 To (WScript.Arguments.Count - 1) Step 2
- WScript.Echo WScript.Arguments(intDrive) & " is mapped to: " & WScript.Arguments(intDrive + 1)
- On Error Resume Next ' ignore already mapped drives
- objNetwork.MapNetworkDrive WScript.Arguments(intDrive), WScript.Arguments(intDrive + 1)
- On Error GoTo 0
- Next
- End If
|