- <?xml version="1.0" encoding="utf-8"?>
- <package xmlns="http://schemas.microsoft.com/WindowsScriptHost">
- <job id="job1">
- <script language="VBScript">
- <![CDATA[
- '
- Option Explicit
- RunasAdmin
-
- On Error Resume Next
- Const wbemFlagReturnImmediately = &h10
- Const wbemFlagForwardOnly = &h20
- Dim objWMIService,objPrinter,strUsbPort,strOut
- strOut = ""
- Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
- For Each objPrinter In objWMIService.ExecQuery("Select * From Win32_Printer Where PNPDeviceID LIKE '%&USB___'", "WQL", wbemFlagReturnImmediately OR wbemFlagForwardOnly)
- strUsbPort = Right(objPrinter.PNPDeviceID,6)
- strOut = strOut & "打印机:" & objPrinter.Name & vbNewLine
- strOut = strOut & "原端口:" & objPrinter.PortName & vbNewLine
- If objPrinter.PortName <> strUsbPort Then
- objPrinter.PortName = strUsbPort
- strOut = strOut & "新端口:" & strUsbPort & vbNewLine
- Else
- strOut = strOut & "未修改" & vbNewLine
- End If
- strOut = strOut & vbnewline
- Next
- If objPrinter Is Nothing Then
- strOut = strOut & "未找到USB打印机."
- End If
- MsgBox strOut, vbOKOnly Or vbInformation Or vbSystemModal, "打印机"
-
-
- Sub RunasScriptHost(strWSH)
- ' runas cscript.exe or wscript.exe
- On Error Resume Next
- If IsNull(strWSH) Or Not (StrComp(strWSH,"cscript.exe",vbTextCompare) = 0 Or StrComp(strWSH,"wscript.exe",vbTextCompare) = 0) Then
- Exit Sub
- End If
- Dim fso
- Set fso = CreateObject("Scripting.FileSystemObject")
- If StrComp(fso.GetFileName(WScript.FullName),strWSH,vbTextCompare) <> 0 Then
- Dim str,arg,shell
- Set shell = CreateObject("Shell.Application")
- str = ""
- For Each arg In WScript.Arguments
- str = str & " """ & arg & """"
- Next
- shell.ShellExecute strWSH,"//nologo """ & WScript.ScriptFullName & """ " & str, "", "open", 1
- Set shell = Nothing
- Set fso = Nothing
- WScript.Quit
- Else
- Set fso = Nothing
- End If
- End Sub
- Sub RunasAdmin()
- On Error Resume Next
- If Not IsVista(".") Then Exit Sub
- Dim wshell
- Set wshell = CreateObject("WScript.Shell")
- wshell.RegRead "HKEY_USERS\S-1-5-19\Environment\TEMP"
- If Err.Number <> 0 Then
- Dim str,arg,shell
- str = ""
- Set shell = CreateObject("Shell.Application")
- For Each arg In WScript.Arguments
- str = str & " """ & arg & """"
- Next
- shell.ShellExecute WScript.FullName,"//nologo """ & WScript.ScriptFullName & """ " & str, "", "runas", 1
- Set shell = Nothing
- Set wshell = Nothing
- WScript.Quit
- Else
- Set wshell = Nothing
- End If
- End Sub
-
- Function IsVista(strComputer)
- On Error Resume Next
- IsVista = False
- Dim objWMIService, colOperationSystems, objOperationSystem
- Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
- Set colOperationSystems = objWMIService.ExecQuery("Select Version from Win32_OperatingSystem")
- For Each objOperationSystem In colOperationSystems
- If CInt(Left(objOperationSystem.Version, InStr(1,objOperationSystem.Version,".") - 1)) > 5 Then
- IsVista = True
- Exit For
- End If
- Next
- Set colOperationSystems = Nothing
- Set objWMIService = Nothing
- End Function
-
- Sub ShowError(lngID)
- If Err.Number <> 0 Then
- WSH.Echo CStr(lngID) & ":Err # " & Err.Number & vbNewLine & _
- "Description: " & Err.Description & vbnewline & _
- "Source: " & Err.Source
- Err.Clear
- End If
- End Sub
- ]]>
- </script>
- </job>
- </package>
复制代码 保存为 .wsf文件; utf-8编码 |