+ Post New Thread
Results 1 to 11 of 11
Scripts Thread, Scripting Problem - Printers in Coding and Web Development; Greetings! I, too, am attempting to use a .vbs script to assign specific printers to specific computers in specific rooms. ...
  1. #1

    Join Date
    Oct 2006
    Location
    Ohio USA
    Posts
    14
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Scripting Problem - Printers

    Greetings! I, too, am attempting to use a .vbs script to assign specific printers to specific computers in specific rooms. I've been reading this, and other threads, on the subject matter, seeing some of the same scripting concept that I'm attempt to use.
    Here is my dilemma-I have named each of my clients with the following structure: RM400-1-PRN1 with the "PRN1" to be used to indicate, in the scripting, the specific printer. In my script, I use the " = right(xxxxx, 3)" but it does not seem to be reading the "PRNx" and mapping the specified printer. Below is the script that I'm trying to use:

    Example 1:

    Dim wshNetwork
    Dim strUsername
    Dim intCnt
    Dim CurrentUser
    Dim strCompName
    Dim strShortName
    Dim PrinterPath
    Set wshNetwork = CreateObject("WScript.Network")

    On Error Resume Next

    wshNetwork.RemoveNetworkDrive "h:"
    wshNetwork.RemoveNetworkDrive "P:"

    wshNetwork.MapNetworkDrive "h:", "\\xxxx\" & wshNetwork.UserName & "$"

    strCompName = wshNetwork.ComputerName

    strShortName = RIGHT(strCompName,4)
    Select Case strShortName

    Case "PRN1"
    PrinterPath = "\\xxxx\LAB1(KOELLER)"
    wshNetwork.AddWindowsPrinterConnection PrinterPath
    wshNetwork.SetDefaultPrinter "\\xxxx\LAB1(KOELLER)"

    Case "PRN3"
    Set objWSHNetwork = CreateObject("WScript.Network") 'create network object
    strConnectString = "\\xxxx\lab2 (open)"
    strResult = objWSHNetwork.AddWindowsPrinterConnection(strConne ctString)
    wshNetwork.SetDefaultPrinter "\\xxxx\lab2 (open)"

    End Select

    WScript.Quit

    or

    Example 2:

    Dim wshNetwork
    Dim strUsername
    Dim intCnt
    Dim CurrentUser
    Dim strCompName
    Dim strShortName
    Dim PrinterPath
    Set wshNetwork = CreateObject("WScript.Network")

    On Error Resume Next

    wshNetwork.RemoveNetworkDrive "h:"
    wshNetwork.RemoveNetworkDrive "P:"

    wshNetwork.MapNetworkDrive "h:", "\\xxxx\" & wshNetwork.UserName & "$"


    strCompName = wshNetwork.ComputerName
    strShortName = RIGHT(strCompName,4)
    Select Case strShortName

    Case "PRN3"
    PrinterPath = "\\xxxx\MediaCtr3500"
    wshNetwork.AddWindowsPrinterConnection PrinterPath
    wshNetwork.SetDefaultPrinter "\\xxxx\MediaCtr3500"

    End Select

    WScript.Quit

    ("xxxx" is sever name)

    If anyone has any suggestions and/or knows what needs to be fixed to correct the problem, it would be greatly appreciated!

    Behuck
    _________________

  2. #2
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,993
    Thank Post
    120
    Thanked 286 Times in 263 Posts
    Rep Power
    108

    Re: Scripting Problem - Printers

    What is it reading in? (if anything at all) do an echo to see what is being read. You may want to covert the the string to lowercase or uppercase as well before doing your case statements.

  3. #3

    Join Date
    Oct 2006
    Location
    Ohio USA
    Posts
    14
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Scripting Problem - Printers

    Chirs

    Pardon my ignorance, but what do you mean by "what is it reading in"?

  4. #4

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,909
    Thank Post
    3,435
    Thanked 1,084 Times in 1,000 Posts
    Rep Power
    370

    Re: Scripting Problem - Printers

    what happens when you run this script on a stand alone machine , also if you get a msgbox to show you what the strShortName stores ie

    msgbox strShortName

    so that when you run the script you can see what strShortName contains exactly.

    when ChrisH says what it is reading in, he means what does the strShortName contain by using a messagebox to prompt you with what that variable contains

  5. #5
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,993
    Thank Post
    120
    Thanked 286 Times in 263 Posts
    Rep Power
    108

    Re: Scripting Problem - Printers

    Code:
    strShortName = RIGHT(strCompName,4)
    After this do a

    Code:
    Wscript.echo strShortName
    I would also try changing the case in the same spot as well.

  6. #6

    Join Date
    Oct 2006
    Location
    Ohio USA
    Posts
    14
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Scripting Problem - Printers

    Chris & Gecko,

    Thx for your input so far - appeciated. I'm not very good with scripting, although I want to learn (and I'm doing so by reading all the posts in this thread-very helpful). I got this script from another "tech" friend at a tech conference and I'm trying to get it to work for me.

    Chris - I'll place the code line "Wscript.echo strShortName" in the script and run it when I get to school on Monday. Please, excuse my ignorance again, but what are you referring to about the "case" and where at exactly(do you mean from "RIGHT" to "right" or are you referring to "PRN1" to "prn1")? I understand it has to do with either upper or lower case, but I'm not sure where you are talking about exactly.

    The other problem I'm having with this script at this time is that when, logged on as a "test student" and connecting to my terminal server (MS Office is located/accessed), I'm in Word and attempt to print a test page, it states that no printers are installed - the script is not following the student's log onto the T-server; I've set the "remote connection" to connect to "printers", but the scripting doesn't seem to follow.

    Thx again for all your advise/assistance!

  7. #7

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,909
    Thank Post
    3,435
    Thanked 1,084 Times in 1,000 Posts
    Rep Power
    370

    Re: Scripting Problem - Printers

    how are you assigning this script ? as a logon or startup script ?

    T-server ? Is that a terminal server ?

    Im guessing you have all your users that need this script in a specific OU in Active Directory ? Could be wrong * shrugs *

  8. #8

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,909
    Thank Post
    3,435
    Thanked 1,084 Times in 1,000 Posts
    Rep Power
    370

    Re: Scripting Problem - Printers

    the other suggestion I have is instead of using right(strShortName,4) and assigning that to a variablbe would be to use the split function instead.

    The reason I say this is because what happens if the PRN numeric value is greater then 1 in length ie PRN30 or PRN02 ??

    Code:
    strCompName = wshNetwork.ComputerName
    strShortName = RIGHT(strCompName,4)
    
    myarray = Split(strShortName,"-")
    msgbox myarray(0)
    msgbox myarray(1) 
    msgbox myarray(2)   '<--- This will be the code that will 
                                    ' return the relevant
              ' machine name ( minus the msgbox )
    Then you would have your select case statements ie

    Code:
    Select Case myarray(2)
    
    Case "PRN1"  '<-- The items in between the quotes are obviously the name of the printer as well as the suffix after the machine name etc so if the machine name matches the suffix ie
    
    RM400-1-PRN1, then any code you have after the case above ie 
    Case "PRN1" then the code that is directly underneath this case will be run each time any machine that the script finds that has PRN1 at the end of it.
    
    So you would now put your code here to do what you need it to do , ie map a printer(s) and set a default one and or map network drives for any machines that end in PRN1
    
    Case "PRN2"
    
    Map any printers or network drives / shares if PRN2 is found
    
    Case Else
    
    ' you can use case else to prompt the user or yourself if any errors occur
    ' you dont need this in here , if this causes problems then delete the
    ' case else along with msgbox err.description.
    
    MsgBox err.description
    
    ' Now that you have all the different cases ie Case "PRN1" , Case "PRN2"
    ' etc you need to tell it that you have done all of them by doing the 
    ' following
    
    End Select
    ' A select case statement is like an if.... else statement but it is easier to
    ' read and follow and understand.

    As for making it follow the user, Im not so sure about that until we establish that the script itself is actually running and that the chunks of code are working with regards to the select case strShortName and making sure that the sub chunks of code underneath PRN1 etc are running as well.

  9. #9
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,993
    Thank Post
    120
    Thanked 286 Times in 263 Posts
    Rep Power
    108

    Re: Scripting Problem - Printers

    If you are usign terminal server then the client computer names will not be picked up as desired using the code you have pasted.
    You need to expand an environment string to find out the client ID. If you look at Rics script in the scripts section you will see this

    Code:
    if (computerName = "svrts1") then _
    	computerName = LCase(WshShell.ExpandEnvironmentStrings("%CLIENTNAME%"))
    What this is doing is saying if the computer name is the terminal server then get the correct client name by expanding the string %clientname% which will return the true name of the client and not of the terminal server.

    As to you question of case I am talking about upper and lower case.
    Before you compare the name of the computer name it is best to change it to all one case because some of you clients maybe "RM400-1-PRN1" and some might be "rm400-1-prn1" or similar and will make the case statement fail top find anything. It may not be the case but it is good practice to do this kind of thing to stop any weird result because someone didnt press shif/have caps lock on when they were naming the PC.

  10. #10

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,909
    Thank Post
    3,435
    Thanked 1,084 Times in 1,000 Posts
    Rep Power
    370

    Re: Scripting Problem - Printers

    If that is true about the upper and lower case then when using split if you do

    select case LCase(myarray(2))

    Case "prn1"

    Case "prn2"

    End Select

    Also if you assign strShortName the expanded client machine name as per chri's suggestion instead of doing it the other way if it is using a terminal server.

    That way when you split the machine name it gets the true machine name.

  11. #11

    Join Date
    Oct 2006
    Location
    Ohio USA
    Posts
    14
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Scripting Problem - Printers

    Chris & Gecko,

    The "T-server" is mentioned is my shortcut for Terminal Server.

    The script is a logon script, set for when each student logons to a client.

    Yes, I have all students in a AD OU - "Students" then listed in individual graduation OUs (2007, 2008, etc.)

    All my clients are named using uppercase (example)"RM400-1-PRN1". The "PRNx" goes only from PRN1 to PRN8, as I have a total of 8 networked printers available for staff/students.

    I will attempt to try both your suggestions when I get back to work on Tuesday (Spring Holiday now).

    THX so much for all your help - God Bless

SHARE:
+ Post New Thread

Similar Threads

  1. I hate printers! Problem with an HP 2550n
    By gwendes in forum Hardware
    Replies: 11
    Last Post: 17th December 2007, 03:46 PM
  2. Replies: 10
    Last Post: 3rd December 2007, 01:12 PM
  3. New to scripting
    By FN-GM in forum Scripts
    Replies: 26
    Last Post: 10th August 2007, 10:31 PM
  4. Problem assigning printers at logon - SOLVED
    By richard in forum Wireless Networks
    Replies: 12
    Last Post: 4th January 2007, 09:14 AM
  5. Scripting IP configuration.
    By Dos_Box in forum Scripts
    Replies: 3
    Last Post: 2nd September 2005, 09:07 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
  •