Solved

vbscript and printers : transfer from one server to one another server

Posted on 2008-10-21
4
340 Views
Last Modified: 2012-05-05
Hi,
We have one old server (windows 2003 server) with printers : the name is print01
I install on a new server which the name is "printnew" with share printers.
I defined a vbscript/Active Directory/GPO  in order to install on client (windows xp) the printers from printnew.
I unshared printer on print01.
The problem is that on client, users have always old share printers from print01.

I would like to know if it s possible to remove all printers from print01 are removed thanks to a script.
Thanks,
Regards
Lirlandais
0
Comment
Question by:lirlandais
  • 2
4 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 250 total points
ID: 22771361
Paste the script below into a text file with a .vbs extension.  Running it will un-map any printers which are connected to shares on the server print01.


'Adapted from http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov07/hey1102.mspx
Const NETWORK = 22
 
Set objNetwork = CreateObject("WScript.Network")
 
strComputer = "."
strServer = "print01"
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")
     
For Each objPrinter in colPrinters
    If objPrinter.Attributes And NETWORK Then
        If LCase(objPrinter.ServerName) = "\\" & LCase(strServer) Then
            strPrinter = objPrinter.Name
            objNetwork.RemovePrinterConnection strPrinter
        End If
    End If
Next

Open in new window

0
 
LVL 5

Expert Comment

by:lecaf
ID: 22771487
other script :)
on small advantage I even delete mappings on the made on the IP
but the other script is cleaner :)

m  a  r  c

'on error resume next
'-------------------------------------------------------------------------------
' Object Creation
'-------------------------------------------------------------------------------
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
'-------------------------------------------------------------------------------
' Main
'-------------------------------------------------------------------------------
DeleteNetPrinters("\\192.168")
DeleteNetPrinters("\\server")
'-------------------------------------------------------------------------------
' Clean up
'-------------------------------------------------------------------------------
Set oPrinters = Nothing
Set WshNetwork = Nothing
wscript.quit(0)

Sub DeleteNetPrinters(ByVAl PrinterServer)
'-------------------------------------------------------------------------------
' Description:  Deletes any Network Printer Present
' Parameters:   begging of printer server url  
'-------------------------------------------------------------------------------
 Set oPrinters = WshNetwork.EnumPrinterConnections
 For i = 1 to oPrinters.Count Step 2
  If Lcase(Left(oPrinters.Item(i),len(PrinterServer))) = PrinterServer Then
   WshNetwork.RemovePrinterConnection oPrinters.Item(i), 1
  End If
 Next
 Set oPrinters = Nothing
End Sub
0
 

Author Closing Comment

by:lirlandais
ID: 31508495
Thanks a million
0
 

Author Comment

by:lirlandais
ID: 22773812
thanks you
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I guess it is not common knowledge to most Wintel engineers/administrators: If you have an SNMP-based monitoring system in your environment (and it's common to have SNMP or Syslog) it's reasonably easy to enable monitoring of the Windows Event logs,…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question