Solved

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

Posted on 2008-10-21
4
343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

So you have two Windows Servers and you have a directory/folder/files on one that you'd like to mirror to the other?  You don't really want to deal with DFS or a 3rd party solution like Doubletake. You can use Robocopy from the Windows Server 200…
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 video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

690 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