Removing Network Printers - Two Quick Questions Please



Good morning!

I have the following VBS script that is working flawlessly in 3.5 of the four parts.


Here is the short version to my two questions. Please find below the longer version of each question along with the logon scrtpt itself.

Q1: when I remove a printer via the logon script it works - the first time - just fine. However, once it is removed everytime the users logon they receive a "The network connection does not exist" - which is expected. How do I build in logic to first check to see if it exists and if it does, remove it...if it does not move on?

Q2: possible to remove all printers that are homed on one server? So, all printers that start out with UNC \\server1\...... would be removed? Is that a smart thing to do? Seems like it would be.

Please find below the logon script the long questions! First, though, please find the script below:

-------------------------------------------------------------------------------------
Option Explicit
Dim objFSO, objNet, objShell, objReg
Dim strPrinter1, strPrinter2, strPrinter3, strPrinter4
Dim bForce, bUpdateProfile
const HKCU = &H80000001

'On Error Resume Next

Set objNet = CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''Remove all Drive Mappings''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

If objFSO.DriveExists("O:")=True Then
objNet.RemoveNetworkDrive "O:",True,True
objReg.DeleteKey HKCU, "Network\" & Left("O:", 1)
End If

If objFSO.DriveExists("P:")=True Then
objNet.RemoveNetworkDrive "P:",True,True
objReg.DeleteKey HKCU, "Network\" & Left("P:", 1)
End If

If objFSO.DriveExists("Q:")=True Then
objNet.RemoveNetworkDrive "Q:",True,True
objReg.DeleteKey HKCU, "Network\" & Left("Q:", 1)
End If


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''Add Drive Mappings''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

objNet.MapNetworkDrive "M:", "\\server\share1"
objNet.MapNetworkDrive "N:", "\\server\share2"
objNet.MapNetworkDrive "O:", "\\server\share3"


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''Remove Old Printers'''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''Add New Printers''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

strPrinter1 = "\\newserver\HP LaserJet 4050 Series PCL 5e"
strPrinter2 = "\\newserver\HP Color LaserJet 4500 PCL 5c"
strPrinter3 = "\\oldserver\Kyocera 3050"
strPrinter4 = "\\oldserver\HP LaserJet 4250 PCL 5e"
objNet.RemovePrinterConnection strPrinter3, True, True
objNet.RemovePrinterConnection strPrinter4, True, True
objNet.AddWindowsPrinterConnection strPrinter1
objNet.AddWindowsPrinterConnection strPrinter2
objNet.SetDefaultPrinter strPrinter1



Set objShell = Nothing
Set objNet = Nothing
Set objFSO = Nothing
Set objReg = Nothing

------------------------------------------------------------------------------------------


The part that is giving me problems is the removal of network printers. Well, actually, that part is not giving me problems I can do that. The problem is that once the printers are actually removed (the first time the user logs on to the machine and the logon script is invoked) every subsequent logon results in an error (something to the effect that "this network connection does not exist"!). Now, that happens - as expected - when I have commented out the On Error Resume Next line. If I 'put it back' (so to speak) then there are no errors and everything is fine and dandy.

What I would like to do is to build in some logic - like I have for the drive mappings - for the removal of the printers. Something to the effect of "If this printer exists, remove it. If not, move on". I am good enough with VBScript to write some basic things and to find scripts (Thank you, Richard!) and modify those to fit the various envioronments that we manage. I just can not quite find the answer to this question! I would like to NOT rely on 'On Error Resume Next'........

Second question - is there a way to simply remove all printers that are shared from "OldServer"? My colleagues have installed a new server at one of our clients and the server that it is replacing is currently the Print Server. Instead of removing each of the five printers that is shared off of "oldserver" individually (read: there would be five entries) I would like to know if it is possible to "simply" remove - in one fell swoop - all of the printers that start out \\oldserver\. I am sure that this can be done. I am just not smart enough to figure it out!

Yes, another novel from me!!!!!!!!!! Sorry everyone. I can not help it!

.



Relevant Pages

  • Re: Removing Network Printers - Two Quick Questions Please
    ... I have the following VBS script that is working flawlessly in 3.5 of the ...  possible to remove all printers that are homed on one server? ... Please find below the logon script the long questions! ...
    (microsoft.public.scripting.vbscript)
  • RE: Printers
    ... the logon script was ... Dim onetwork, sprintpath ... pointing to each printer individually with the final vbs script to be ... > server, I am however having problems setting up printers, ...
    (microsoft.public.windows.server.general)
  • Re: Printers via GPO scripts?
    ... Removing printers installed that way is a bit more difficult than simply ... removing the line of code from the logon script. ... "Tim Guy" wrote in message ... >> Assign this scripts as an logon script within a GPO. ...
    (microsoft.public.win2000.group_policy)
  • Re: Printer Script by OU 2008 TS
    ... - No it doesn't work from a Vista client via RDC ... TS the script is set to delete any printers and then map the correct one ... The logon script failed to add printer on TS Server for CE 5 Pro thin ...
    (microsoft.public.windows.group_policy)
  • Re: Need help invoking logon script after logging in to VPN authenticated by RSA software token
    ... Tokens for VPN authentication, and it changes the order of the login ... Cisco VPN client appears before the Windows GINA. ... The logon script maps drives for the user. ...
    (microsoft.public.windows.server.scripting)

Loading