Re: Checking printers exist

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"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


.



Relevant Pages

  • Re: Checking if printers exist.
    ... Set objNetwork = CreateObject ... use their laptop at home it will throw up an error basically saying ... this other than making the script simply ignore errors. ...
    (microsoft.public.scripting.vbscript)
  • Re: STDIN on the fileevent handle
    ... gets endless messages and continues to read blank lines. ... able on the underlying device. ... end of file or error condition is present on the underlying file or ... for end of file, an infinite loop may occur where script reads no data, ...
    (comp.lang.perl.tk)
  • Re: Connection attempts
    ... >>Script kiddies..just ignore it and get used to it. ... > I don't suggest ignoring the 'kiddies' that walk down the street trying to ... Kris ...
    (FreeBSD-Security)
  • Re: [kde] KDE menus (Lancelot, Kmenu, Krunner) not respecting PATH?
    ... PATH and using the system PATH. ... "thunderbird" which sets environment variables for the Thunderbird ... script in $HOME/.bin however when I lauch "thunderbird" from Krunner I ... These applications aren't ignoring your PATH. ...
    (KDE)
  • Re: Connection attempts
    ... >Script kiddies..just ignore it and get used to it. ... I don't suggest ignoring the 'kiddies' that walk down the street trying to ... with "unsubscribe freebsd-security" in the body of the message ...
    (FreeBSD-Security)