i need help, i need to change the print port from USB001 a USB002 using vscript

  • Thread starter Thread starter ARGJ
  • Start date Start date
A

ARGJ

Guest
hi, some body knows how to change print port using vbscript i want to change the print port from USB001 to USB002 when users performance logig, i have sevarals day looking this information on internet but i can't find it.


This is my script for sharing the print and map to lpt1 this for a old system


Dim objWMIService, objService
Dim strService,strComputer, PrintPortType, PrtName
PrtName = "TMUCASH"
PrintPortType = "USB"
strService="MpsSvc"
strComputer = "."
Set wshShell = CreateObject( "WScript.Shell" )
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

IF InStr(strComputerName,"CASH") THEN
IF printerExists("Generic / Text Only") THEN
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer Where Name = 'Generic / Text Only' AND PortName LIKE '%USB%'")

For Each objPrinter in colInstalledPrinters
If objPrinter.Shared = False Then
objPrinter.Shared = True
objPrinter.ShareName = PrtName
On Error Resume Next
objPrinter.Put_
msg = Err.Description
On Error GoTo 0
If msg <> "" Then
MsgBox "Cannot share " & objPrinter.Name & ": " & msg
End If
End If
Next

Set objShell = CreateObject("WScript.Shell")
strCmd = "net use lpt1 \\"& strComputerName & "\"& PrtName & " /persistent:yes /YES"
set objExec = objShell.Exec(strCmd)

Else

END IF
END IF

Function printerExists(str)
printerExists = False
Dim objWMIService
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Dim colPrinters
Set colPrinters = objWMIService.ExecQuery("Select * from Win32_Printer Where Name = 'Generic / Text Only' AND PortName LIKE '%USB%'")

Dim objPrinter
For Each objPrinter In colPrinters
If objPrinter.Name = str Then
printerExists = True
Exit For
End If
Next
End Function

Continue reading...
 
Back
Top