Solved

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

Posted on 2008-10-21
4
341 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

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,…
Numerous times I have been asked this questions that what is it that makes my machine log on so slow, there have been cases where computers took 23 minute exactly after taking password and getting to the desktop. Interesting thing was the fact th…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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