remove all printers on a client from a specific server

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi all,

i would like to write a vb script wich deletes all
network printer connection on a client to specific server.
 
'
'Program Name: removeprinters.VBS
'
'Author Antony Samuel
'
'Description VBS for removing network printers list.
'
'-----------------

Option Explicit
On Error Resume Next

'-----------------
'global variables


Dim WSHShell, WshProcessEnvironment, EnvTempDir, oNet, oWshNetwork
Dim PrinterServer, objShell, objFileSystem, objTextStream, nReturnCode, iPos
Dim objTextFile, sRead, sReadLine, sReadAll, sSkipChar, SskipLine

'-----------------

'Objects


Set oNet = CreateObject("Wscript.Network")


'-----------------


'Function Calls

PrinterServer="\\Print_Server"
Printer="Printer_Name"
RemovePrinter(PrintServer, Printer)

'this is the end of the function
calls
'-----------------
'Remove Printer maping

Function RemovePrinter(PrintServer, Printer)
'On Error Resume Next
Dim oPrinter, PrtServer, PrtName, Prt

Prt = PrintServer & Printer 'Strip backslashes from UNC names
PrtServer = Left(Prt,InStr(3,Prt, "\") - 1)
PrtServer = Right(Left(Prt,InStr(3,Prt, "\") - 1), Len(PrtServer) - 2)
PrtName = Right(Prt, Len(Prt) - Len(PrtServer) - 3)

' On Error Resume Next 'If printer or server dosen't exist,
code continues execution

Set oPrinter = GetObject("WinNT://" & oNet.UserDomain & "/" & PrtServer
& "/" & PrtName)

If (oPrinter.Name = "" OR oPrinter.Class <> "PrintQueue") Then
Wscript.Echo("Printer " & PrintServer & oPrinter.Name & " is not a
valid network printer")
Else
oNet.RemovePrinterConnection(PrintServer & Printer)
Wscript.Echo("Removeing printer Mapping to " & PrintServer &
Printer)
End If

End Function

'-----------------


Regards,
Antony
____________________________________________________________
Antony Samuel Naiim
M.I.T. -Nottingham Univ. - U.K.
Information systems Dept.
Apache Egypt companies
Web: www.apachecorp.com
____________________________________________________________
hi all,

i would like to write a vb script wich deletes all
network printer connection on a client to specific server.
 
Back
Top