Re: Checking printers exist
- From: "Al Dunbar" <AlanDrub@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 12 Apr 2007 17:34:00 -0600
"Bebarce" <Bebarce@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:243892F6-3466-4A21-BDC9-B48F79B16D52@xxxxxxxxxxxxxxxx
I've created a fairly simple script and set it into the All Users Start up
directory
Set objNetwork = CreateObject("Wscript.Network")
objNetwork.AddWindowsPrinterConnection "\\printserver\OldPrinter", true
objNetwork.RemovePrinterConnection "\\printserver\Oldprinter", true, true
objNetwork.AddWindowsPrinterConnection "\\printserver\NewMainPrinter",
true
objNetwork.AddWindowsPrinterConnection "\\printserver\NewBackupPrinter",
true
objNetwork.SetDefaultPrinter "\\printserver\NewMainPrinter"
Originally i was having a problem where if the old printer was already
removed it would throw out an error saying there is no printer to remove.
I
seemed to havefixed that by adding the printer, and than removing the
printer.
But then if the old printer hadn't been removed, you would be ignoring that
fact when re-adding it, so why not...
My main problem however is that if this script runs on a laptop, when they
use their laptop at home it will throw up an error basically saying there
is
no printer available to install. What is the easiest way for me to
resolve
this other than making the script simply ignore errors.
.... why not do it that way? Except in those cases where the potential for
harmful side effects exists, the code that is the most effective in
determining if an action will throw an error is to run that code.
I think the best
option would be to some how tell the program to check if the printer
connection exists, and if so than proceed with the code, if not end.
Why, exactly, do you feel that it is better to try writing your own code to
anticipate errors that might happen? It will almost certainly be more
complex than just running some code and either detecting or ignoring the
resulting error condition.
Is it perhaps that the word "ERROR" seems to imply that there is something
wrong, or, worse yet, that there is an ERROR in your code? If so, try to
think of these things as "exceptional conditions" instead of errors, and
that using the intrinsic error handling functionality is simply a technique,
not to avoid or prevent errors, but to get your script to accomplish what
you want it to do.
Anyone
can help me with the code/syntax?
I am sure someone else can - I have never written code like that.
/Al
.
- Prev by Date: Re: Need WMI script
- Next by Date: Re: Using WMI to disable a user account
- Previous by thread: recycle windows service
- Next by thread: Re: Using WMI to disable a user account
- Index(es):
Relevant Pages
|