Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Sun Nov 08, 2009 8:33 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ]  Bookmark and Share
Author Message
 Post subject: Logon Script to remove old printers or changed names??HELP
PostPosted: Thu Apr 02, 2009 5:06 pm 
Offline

Joined: Thu Apr 02, 2009 7:03 am
Posts: 1
Hi I am working on a vbs logon script that will add/remove network printers.
************BACKGROUND*************
We currently, use a logon script to add printers it works fine, but users where complaining that the naming convention was confusing so we changed the name of the printers. the problem arises that now they have old (invalid) printers on their computer.

My goal is to have a script that pulls a list of shared printers from the print server and maps those to client machines at logon AND it removes any invalid shared printers on the client machine (those shared non-local printers no longer being served up by the print server).

********** QUESTION **************
HOW DO I REFERENCE AND MAPPED NETWORK PRINTER THAT IS NO LONGER VALID AS A PRINTER. E.G. THE PRINTER NAME HAS CHANGED OR THE PRINTER HAS BEEN REMOVED TOTALLY.

MY CODE: MANY THANKS IN ADVANCE

Option Explicit
'On error resume next
' variables are defined here
Dim strComputer, objNetwork, objWMIService, colInstalledPrinters, objPrinter, strUNCPrinter, defaultPrinter ,strlocalComputer
Dim objlocalWMIService
' ***********************************************************
' this portion of the script will remove all shared printers
' find the printer currently defined as default and save it
' *************************************************************

' This sets the computer to all local machines
strlocalComputer = "."

Set objNetwork = CreateObject("WScript.Network")
' this is the Windows management Service object a query will be executed on
Set objlocalWMIService = GetObject("winmgmts:")

' The local mahcine is queried for all shared printers.
' The data is placed in an Array
Set colInstalledPrinters = objlocalWMIService.ExecQuery _
("SELECT * FROM Win32_Printer")

' iterate through array deleting all returned printer objects
For Each objPrinter in colInstalledPrinters
Wscript.Echo "Name: " & objPrinter.Name & " _-_ Location: " & objPrinter.SystemName & " _-_ DeviceID =" & objPrinter.DeviceID
'Wscript.Echo "Name: " & objPrinter.DeviceID
' check for default printer status if true name value is stored for later use

If objPrinter.Default = True Then
defaultPrinter = objPrinter.Name
End If
' printer is removed
'objNetwork.RemovePrinterConnection objPrinter.DeviceId
Next

' ##################################################################################################
' This section is where the shared printers on ABOR1 are found and added to the local machine
' the default printer is defined above and used in the last step.
' ###################################################################################################

' define the machine being queried for this purposes ABOR1.
strComputer = "ABOR1"

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

' This query will pull all shared printer objects that have a location of ABOR
' if the location field in the printer is not = ABOR this script will not add it.

Set colInstalledPrinters = objWMIService.ExecQuery _
("SELECT * FROM Win32_Printer where Shared = True and Location = 'ABOR'")
'iterate through array adding all shared printer objects found on ABOR1
For Each objPrinter in colInstalledPrinters
'Printer name is constructed here \\server\printer
strUNCPrinter = "\\" & objPrinter.SystemName & "\" & objPrinter.ShareName
' printer is added here
'objNetwork.AddWindowsPrinterConnection strUNCPrinter

Next
'Sets the default printer after all printers have been added this comes from
if defaultPrinter <> "" then
objNetwork.SetDefaultPrinter defaultPrinter
End if


Last edited by buttabrick on Wed Apr 08, 2009 4:48 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Logon Script to remove old printers or changed names
PostPosted: Wed Apr 08, 2009 8:56 am 
Offline
100+ Club

Joined: Tue Jan 20, 2009 7:34 am
Posts: 237
i must say that it is cool.

_________________
aciphex,herbal phentermine,lamisil


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley