Results 1 to 6 of 6

Thread: HELP Printers VBS script

  1. #1
    Registered+
    Join Date
    Dec 2004
    Posts
    49
    Thanks
    0
    Thanked
    0 times in 0 posts

    HELP Printers VBS script

    I want to add a printer to a computer called class1w-a

    The printer is currently on class1w-b the printer is shared as class1w-690

    I tried to use the following script and i doesn't work any ideas what im doin wrong?

    The following is saved in notepad as "printers.vbs"


    On Error Resume Next

    Set WshNetwork = WScript.CreateObject("WScript.Network")

    compname = UCase(WshNetwork.ComputerName)

    sub removenetworkprinters

    set oPrinters = WshNetwork.EnumPrinterConnections

    For i = 0 to oPrinters.Count - 1 Step 2

    uncpath = oPrinters.Item(i+1)

    if Left(uncpath, 2) = "\\" then

    WshNetwork.RemovePrinterConnection uncpath, true, true

    end if

    Next

    end sub

    sub addprinter(partname, printpath)

    if Instr(compname, partname) <> 0 then

    WshNetwork.AddWindowsPrinterConnection(printpath)

    end if

    end sub

    sub makedefault(partname, printpath)

    if Instr(compname, partname) <> 0 then

    WshNetwork.SetDefaultPrinter printpath

    end if

    end sub

    ''''''''''''''''''''''''''''''''
    ' Main Block
    ''''''''''''''''''''''''''''''''

    addnetworkprinters

    addprinter "class1w-a", "\\class1w-b\class1w-690"

  2. #2
    Senior Member
    Join Date
    Jul 2003
    Location
    ZA ✈ UK
    Posts
    622
    Thanks
    0
    Thanked
    0 times in 0 posts
    Code:
    On Error Resume Next
    
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    
    compname = UCase(WshNetwork.ComputerName)
    
    sub removenetworkprinters
      set oPrinters = WshNetwork.EnumPrinterConnections
    
      For i = 0 to oPrinters.Count - 1 Step 2
        uncpath = oPrinters.Item(i+1)
        if Left(uncpath, 2) = "\\" then
          WshNetwork.RemovePrinterConnection uncpath, true, true
        end if
      Next
    end sub
    
    sub addprinter(partname, printpath)
      if Instr(compname, partname) <> 0 then
        WshNetwork.AddWindowsPrinterConnection(printpath)
      end if
    end sub
    
    sub makedefault(partname, printpath)
      if Instr(compname, partname) <> 0 then
         WshNetwork.SetDefaultPrinter printpath
      end if
    end sub
    
    ''''''''''''''''''''''''''''''''
    '  Main Block
    '''''''''''''''''''''''''''''''' 
    addnetworkprinters
    addprinter "class1w-a", "\\class1w-b\class1w-690"
    There, that looks a lot better.

    There are numerous things wrong with that code. The sub-routines removenetworkprinters and makedefault go unused, while a referenced sub, addnetworkprinters, doesn't exist.


    As far as I can tell, though, the following is all you really need:

    Code:
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    WshNetwork.AddWindowsPrinterConnection "\\class1w-b\class1w-690"
    Note, though, that this code will only work under Windows 2000/XP. Windows 9x/Me require that you specify the printer driver in addition to its location. For the documentation and examples (Both 2000/XP and 9x/Me) on the AddWindowsPrinterconnection function, see http://msdn.microsoft.com/library/de...connection.asp

    Hope you come right.

  3. #3
    Senior Members' Member Matt1eD's Avatar
    Join Date
    Feb 2005
    Location
    London
    Posts
    2,462
    Thanks
    0
    Thanked
    0 times in 0 posts
    • Matt1eD's system
      • Motherboard:
      • MSI K9N6SGM-V GeForce 6100
      • CPU:
      • Athlon 64 LE-1620 2.41GHz
      • Memory:
      • 2 GB DDR2
      • Storage:
      • 1.25 TB
      • Graphics card(s):
      • Onboard
      • PSU:
      • eBuyer Extra Value 500W!
      • Operating System:
      • XP Pro
    Why do you need this? You could do it through Active Directory or printer installation.

  4. #4
    Senior Member
    Join Date
    Jul 2003
    Location
    ZA ✈ UK
    Posts
    622
    Thanks
    0
    Thanked
    0 times in 0 posts
    Matt1eD - It could be that this needs to be run on an entire network of workstations. As such, it'd be far easier to just include this script as part of the logon process, than to manually add the printer to each machine.

  5. #5
    Senior Members' Member Matt1eD's Avatar
    Join Date
    Feb 2005
    Location
    London
    Posts
    2,462
    Thanks
    0
    Thanked
    0 times in 0 posts
    • Matt1eD's system
      • Motherboard:
      • MSI K9N6SGM-V GeForce 6100
      • CPU:
      • Athlon 64 LE-1620 2.41GHz
      • Memory:
      • 2 GB DDR2
      • Storage:
      • 1.25 TB
      • Graphics card(s):
      • Onboard
      • PSU:
      • eBuyer Extra Value 500W!
      • Operating System:
      • XP Pro
    spose. I appreciate not everyone uses AD, but he could do it through AD aswell (or then if @ home then a script would work best for multiple comps).

  6. #6
    Account closed at user request
    Join Date
    Aug 2003
    Location
    Elephant watch camp
    Posts
    2,150
    Thanks
    56
    Thanked
    115 times in 103 posts
    • wasabi's system
      • Motherboard:
      • MSI B85M-G43
      • CPU:
      • i3-4130
      • Memory:
      • 8 gig DDR3 Crucial Rendition 1333 - cheap!
      • Storage:
      • 128 gig Agility 3, 240GB Corsair Force 3
      • Graphics card(s):
      • Zotac GTX 750Ti
      • PSU:
      • Silver Power SP-S460FL
      • Case:
      • Lian Li T60 testbanch
      • Operating System:
      • Win7 64bit
      • Monitor(s):
      • First F301GD Live
      • Internet:
      • Virgin cable 100 meg
    This is easier, but not VB (its how I do it at work)

    http://www.robvanderwoude.com/index.html

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Im looking for a CS: S Server Script.
    By Daymonkey in forum Software
    Replies: 6
    Last Post: 22-02-2005, 01:39 AM
  2. network printers
    By Flibb in forum Networking and Broadband
    Replies: 1
    Last Post: 21-02-2005, 12:09 PM
  3. printers!
    By shiato storm in forum PC Hardware and Components
    Replies: 13
    Last Post: 17-02-2005, 12:34 PM

Posting Permissions

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