Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2002
    Melbourne, Victoria, Australia
    Thanked 0 Times in 0 Posts

    Add printer script

    I have an add printers script that I am having trouble with. I am fairly new to scripting so it's probably something pretty simple. The line that I am having trouble with starts 'Set fserv'. Can anybody help???

    Dim FileSys, printerpath, prt, UcaseRoom, room
    Dim objWshPrint
    Dim objPrn

    Set objWshPrint = WScript.CreateObject("WshPrint.Printers")

    'On error resume next
    room = InputBox("Enter first 4 characters of printer:","Printer search by room number")

    'make it uppercase
    UcaseRoom = ucase (room)

    'Print server name.
    ComputerName = "WinNT://CRIPPS-PRINT"
    Set fserv = GetObject(ComputerName)
    'Do it for each share
    For each share in fserv
    'If it is a printer share..
    if share.class = "PrintQueue" then
    prt =
    'Since we identify printers by the first 4 characters i.e.: (room#Printername, A2002HPLJ4SI )...
    LeftString = Left(prt, 4)
    'Compare both strings
    compsh = strcomp (LeftString, UcaseRoom)
    'If they are the same..
    if compsh =0 then
    'Build printer pathname
    Printerpath = ""&""&prt
    'Add the printer
    prn = objWshPrint.AddPrinter(Printerpath)
    end if
    end if

    'Enumerate all printers available.
    PrinterList = objWshPrint.EnumPrinters
    MsgBox ("Your defined printers are: "& Printerlist)

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 94 Times in 90 Posts

    Re: Add printer script

    I don't think I can help much, I get this error:

    Could not locate automation class named "WshPrint.Printers".

    The code

    ComputerName = "WinNT://CRIPPS-PRINT"
    Set fserv = GetObject(ComputerName)

    is foreign to me. I usually see a COM object as the object for GetObject, or a file.

    There is an alternative method for adding printer connections described in Windows Script Host: AddWindowsPrinterConnection Method. However, it doesn't cover enumeration. Hmmm...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts