|
Guy recommends :
Find out which of your VMs are a waste of space and which VMs need more resources. |
VBS Logon Scripts - RemovePrinterConnectionUse VBScript To Remove a PrinterOccasionally Windows logon scripts need the RemovePrinterConnection method. So I will provide two worked examples of how to remove unwanted printer icons from the Printers and Faxes folder. Topics for RemovePrinterConnection
♦ Remove Printer With VBScript ScenarioI find that printer logon scripts do not need RemovePrinterConnection as much as mapping network drives need RemoveNetworkDrive. The reason is that if you map the same printer repeatedly you don't get the error: 'The local device name is already in use'. Surprisingly, the script just maps the new printer over the old one. Nevertheless, removing an existing printer is useful when your scripts are at the testing stage and you don't want to keep going to the Printer and Faxes folder, right clicking the printer and selecting: Delete. RemovePrinterConnection ArgumentsTo get rid of a printer icon, most of the time, all that you need is the method, RemovePrinterConnection and the printer name. For example, objNetwork.RemovePrinterConnection
strUNCPrinter (Network Printer) Mastering the basics of RemovePrinterConnection are easy. If there is a danger it's adding, un-needed, unnecessary syntax. For instance there is no need for a comma before the printer name. Even mastering the extra arguments is not difficult, however, in this instance you do need commas between the last three arguments, here is the full syntax: RemovePrinterConnection strDriveLetter, bForce, bUpdateProfile It was a long time before I realized that the prefix b, in bForce and bUpdateProfile meant Boolean. Once I understood this significance, it became obvious why there were only two possible values, true or false. bForce means remove the printer - even if its in use. (My friend 'Mad' Mick thinks bForce means brute force and he is not far wrong.) Setting bUpdateProfile to "true" tells VBScript to update the user's profile. Example 1a - Preparation RemovePrinterConnectionEven though RemovePrinterConnection is straightforward, we still need preparation. So we must create a printer, otherwise, there would be nothing to remove and all you would get is Error: 'This network connection does not exist'
' PrintersLong.vbs - Windows Logon Script example. Guy Recommends Solarwinds' Free Network Monitor![]() Thus utility makes it easy to check the health of your router or firewall. Check the real-time performance, and availability statistics, for any device on your network. Get started with an extensive collection of "out-of-the-box" monitors for popular network devices. Download your free Network Device Monitor Example 1b - Delete the printer icon with RemovePrinterConnectionInstructions for RemovePrinterConnection
' RemovePrinterConnection.vbs - Windows logon script VBS Learning PointsNote 1: The basic RemovePrinterConnection is a simple command with no commas and only one argument - the drive letter. Note 2: If you need to remove a local printer, all you need to do is place its name in quotes "HP Laserjet 6l" Example 2 - Full RemovePrinterConnection SyntaxJust in case you need the bForce or the bUpdateProfile switch, here is an example of the full RemovePrinterConnection command with all three arguments. Instructions to RemovePrinterConnection
' ' RemPrinterbForce.vbs - Windows logon script sample Learning PointsNote 1: Spot the bForce, and bUpdateProfile commands, "true" and "false" respectively. You may wish to replace with "true", "true" in your production script. Note 2: In the RemoveNetworkDrive method the bForce makes a difference, but here with RemovePrinterConnection it does not make much difference. My point is that even without bForce, the script deleted my printer, even though it had a print job. I even explicitly added bForce "False". Anyway, no big deal.
Guy
Recommends: Permissions Analyzer - Free Active Directory Tool
|
||||
Custom Search
|
Guy Recommends: WMI Monitor and It's Free!
|
|
Home Copyright © 1999-2012 Computer Performance LTD All rights reserved Please report a broken link, or an error. | |