+ Post New Thread
Results 1 to 3 of 3
Scripts Thread, Printing by location in Coding and Web Development; I noticed on Wiki there was a script whereby you can print according to your room location. I've adapted it ...
  1. #1

    Join Date
    Jun 2008
    Posts
    701
    Thank Post
    118
    Thanked 58 Times in 48 Posts
    Rep Power
    25

    Printing by location

    I noticed on Wiki there was a script whereby you can print according to your room location.

    I've adapted it and was wondering if anyone could have a look to see what I have done is right and correct me where I'm not. By the way, I've never dabbled in vbscript before and this is my first. I've tried it today but it didn't work. It didn't delete any of the current printers for a user and nor did it replace it with printers according to the room name.

    Please help. Many thanks in advance.




    ' Script to add network printers to workstations and thin clients
    ' Author: Ric Charlton

    ' Declare variables and enumerate existing printer connections
    On Error Resume Next


    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set oPrinters = WshNetwork.EnumPrinterConnections

    Dim computerName
    computerName = LCase(WshNetwork.ComputerName)


    ' Delete existing connections to network printers
    For i = 0 to oPrinters.Count - 1 Step 2

    On Error Resume Next

    if Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" then

    WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true

    else WScript.Echo "No network printers found"

    end if

    Next



    ' Citrix specific section

    if (Left(computerName, 5) = "svrts") then

    computerName = LCase(WshShell.ExpandEnvironmentStrings("%CLIENTNA ME%"))

    end if


    I deleted this bit in bold but I got an error about the next command missing or something. Should I remove the next because we don't have a citrix here?



    ' Add printer connections dependant upon location
    ' Variable to select print server
    Dim printServer
    printServer = "MyFirstPrintServer"

    Dim x

    x = split(computerName,"-")

    Select Case x(0)


    I added this bit which replaced Select Case (Left(computerName, 4))



    Case "room01"

    WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\RM01-MONO"

    WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\RM01-COLOUR"

    WshNetwork.SetDefaultPrinter "\\" & printServer & "\RM01-MONO"

    Case "room02"

    WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\RM02-MONO"

    WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\RM02-COLOUR"

    WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\RM02-A3"

    WshNetwork.SetDefaultPrinter "\\" & printServer & "\RM02-MONO"

    End Select

  2. #2

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,582
    Thank Post
    107
    Thanked 761 Times in 592 Posts
    Rep Power
    179
    You should be able to delete the Citrix section without a problem.

    Could you paste in the errors you receive? (Run the script at the command prompt so you can copy and paste).

    Could you also give us an example of your computer names so that we can check that you are inspecting them correctly.

  3. #3

    Join Date
    Jun 2008
    Posts
    701
    Thank Post
    118
    Thanked 58 Times in 48 Posts
    Rep Power
    25
    Using the script I pasted earlier, how would you get it to map local printers that are either connected using a LPT1 connection or USB?

    I think the script is kinda working but throws up errors when I try to add locally attached printers.

SHARE:
+ Post New Thread

Similar Threads

  1. Printer Location Awareness
    By techie08 in forum Windows
    Replies: 7
    Last Post: 23rd May 2008, 09:41 AM
  2. Installing printers by location
    By Osprey in forum How do you do....it?
    Replies: 6
    Last Post: 25th February 2008, 01:47 PM
  3. cgi-bin location
    By dezt in forum Web Development
    Replies: 7
    Last Post: 13th October 2007, 10:10 PM
  4. Location?
    By witch in forum Comments and Suggestions
    Replies: 14
    Last Post: 7th September 2007, 06:20 PM
  5. location in posts
    By goodhead in forum General Chat
    Replies: 1
    Last Post: 1st March 2007, 10:14 AM

Thread Information

Users Browsing this Thread

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

Posting Permissions

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