回复 9# 5i365
关于如何获得管理员至高无上权限的方法,自行百度。下面这个可以检测是否获取最高权限。- Option Explicit
- On Error Resume Next
- Dim strDriveLetter,objWbemService,colVolumes,objVolume,retValue
- Set objWbemService = GetObject("winmgmts:{ImpersonationLevel=Impersonate}!//./root/cimv2")
- objWbemService.Get "Win32_LogonSession.LogonId='999'"
- If Err.Number <> 0 Then
- ' ShowError
- WSH.Echo "Lower Privilege.权限太低了。"
- Set objWbemService = Nothing
- WSH.Quit 1
- End If
- strDriveLetter = "D"
- Set colVolumes = objWbemService.ExecQuery("Select DeviceID,DriveLetter,Label,Name,SerialNumber From Win32_Volume Where BootVolume=False And SystemVolume=False And DriveType=3")
- For Each objVolume In colVolumes
- If LCase(Left(objVolume.Label,3)) = "win" Then
- WSH.Echo "Dismounting volume: " & objVolume.DriveLetter & " with Label: " & objVolume.Label
- retValue = objVolume.Dismount(True,True)
- If retValue = 0 Then
- WSH.Echo "Success"
- Else
- WSH.Echo "Failed : " & retValue
- End If
- ' ShowError
- Else
- If UCase(Left(objVolume.DriveLetter,1)) <> strDriveLetter Then
- WSH.Echo "Assign new driveLetter: " & objVolume.DriveLetter & ": to " & strDriveLetter & ":"
- ' retValue = objVolume.Dismount(True,False)
- objVolume.DriveLetter = strDriveLetter & ":"
- ' retValue = objVolume.Mount()
- End If
- If strDriveLetter = "Z" Then Exit For
- strDriveLetter = Chr(Asc(strDriveLetter) + 1)
- End If
- ' WSH.Echo objVolume.DriveLetter & vbTab & objVolume.DeviceID
- Next
- Set objVolume = Nothing
- Set colVolumes = Nothing
- Set objWbemService = Nothing
复制代码
|