Solved

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

Posted on 2008-10-21
4
338 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks a million
0
 

Author Comment

by:lirlandais
Comment Utility
thanks you
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now