Deleting and re-installing printer with new name using login scrip

Discussion in 'Scripting' started by Ronnie, Feb 4, 2009.

  1. Ronnie

    Ronnie Guest

    Hi all,

    I want to change the naming standard for all printers in my company. This
    goes for both the sharenames and printer names. The idea is that I'll do this
    outside normal working hours and then for a period of time update the login
    script so that it first checks if a network printer is installed, and if this
    is the case it deletes the network printer and then re-installs it with the
    new name. This will be done for each network printer in the company, and if
    the printer isn't installed on the specific pc the script will just move on
    to check for the next printer. However I can't get this to work properly.

    This is an example of the script for a printer with old printer name OKI
    C5600 and sharename OKIC5600 and new printer name Herlev - Stuen - ANBL - Oki
    C5600 and sharename ANBLOkiC5600:

    if not exist \\fs\OKIC5600 goto ok_OKIC5600
    rundll32 printui.dll,PrintUIEntry /dn /n\\fs\OKIC5600 /j"OKI C5600"
    rundll32 printui.dll,PrintUIEntry /in /n\\fs\ANBLOkiC5600 /j"Herlev - Stuen
    - ANBL - Oki C5600"

    Can anybody tell me why this isn't working? If I rem out the first line the
    printer is succesfully deleted, so there must be a problem in the "if not
    exist......" line.

    Thanks in advance,
    Ronnie, Feb 4, 2009
    1. Advertisements

  2. Ronnie

    Al Dunbar Guest

    Is \\fs\OKIC5600 a file or a folder, and does it exist?

    Al Dunbar, Feb 4, 2009
    1. Advertisements

  3. Ronnie

    Ronnie Guest

    fs is the name of the file server and OKIC5600 is the old sharename for the
    printer which I by the time the script is supposed to run will have changed
    to ANBLOkiC5600.

    Ronnie, Feb 4, 2009
  4. Ronnie

    Ronnie Guest

    I actually think the problem is that "if not exist \\fs\OKIC5600 goto
    ok_OKIC5600" looks for a printer with the sharename OKIC5600 on the print
    server named fs, and this no longer exists since I've changed the sharename
    to ANBLOkiC5600, and because this no longer exists on the print server it
    goes to ":eek:k_OKIC5600".

    So the challenge is to change the \\fs\OKIC5600 part to instead search for
    the network printer on the local pc, but how can I do this so it works for
    all pc's in the domain? Is there a command to select the local pc name like
    you can use "%username%" to specify the user logged in on a pc?

    Ronnie, Feb 4, 2009
  5. Ronnie

    Al Dunbar Guest

    .... in which case the if not exist would seem to always succeed - even if
    the printers in the local profile stil had a reference to it.

    I know that if exist can test the existence of a shared folder by giving its
    UNC, but I don't know if this works for a UNC to a non-NTFS object such as a
    shared printer.

    Al Dunbar, Feb 4, 2009
  6. Ronnie

    Al Dunbar Guest

    IF ? sheds a bit of light on what this means:

    IF [NOT] EXIST filename command

    so it would appear that it knows little of shared printers, and deals only
    with file-related objects.
    of because no shared folder exists by that name.
    You could use \\%computername%\share to test for the existence of a
    specified shared folder on the local computer, but I do not think that is
    the way to go.

    First, and as already stated, IF EXIST looks for file type objects. Second,
    even if the method would work, it would only detect printers shared out by
    the PC, not those shared out by a server and only referenced by a user on
    the PC.

    I'm not sure of a simple way to accomplish what you want using batch, but
    suspect it would be relatively simple to do with vbscript/WSH using the
    network object:

    Al Dunbar, Feb 4, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.