+ Post New Thread
Results 1 to 12 of 12
Scripts Thread, Terminal server logon script for printers in Coding and Web Development; I've altered my printer script to add a section for Citrix clients but i can't get them to add when ...
  1. #1
    cookie_monster's Avatar
    Join Date
    May 2007
    Location
    Derbyshire
    Posts
    4,203
    Thank Post
    394
    Thanked 278 Times in 239 Posts
    Rep Power
    74

    Terminal server logon script for printers

    I've altered my printer script to add a section for Citrix clients but i can't get them to add when logging onto the citrix box but it will add the correct client from a windows xp client. I'm not sure where the %CLIENTNAME% info is collected from so i'm not sure i have that right.

    Can anyone suggest what is wrong?

    Cheers.

    Code:
    On error resume next
    
    Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Network, computerName, room, WSHPrinters, LOOP_COUNTER, Path
    
    
    Set objDomain = getObject("LDAP://rootDse")
    DomainString = objDomain.Get("dnsHostName")
    Set WSHNetwork = CreateObject("WScript.Network")
    Set Network = CreateObject("Wscript.Network") 
    computerName = LCase(WshNetwork.ComputerName)
    room = left(computerName,3)
    
    
    
    '-------------------------------------------------------------
    '-------------------------------------------------------------
    
    
    'Remove ALL old printers
    'Enumerate all printers first, after that you can select the printers you want by performing some string checks
    Set WSHPrinters = WSHNetwork.EnumPrinterConnections
    For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
    'To remove only networked printers use this If Statement
        If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
          WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
        End If
    'To remove all printers incuding LOCAL printers use this statement and comment out the If Statement above
    'WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
    Next
    
                                   
    
    'Give the PC time to disconnect old printers, wait 3000 milliseconds
    wscript.sleep 3000
    
    
    
    'Set local printer to default
    '------------------------------------------------------------
    
    Set WSHPrinters = WSHNetwork.EnumPrinterConnections
    For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
    'Find local printers
        If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) <> "\\" Then
          WSHNetwork.SetDefaultPrinter _              
                  (WSHPrinters.Item(LOOP_COUNTER +1))
        End If
    Next
    
    
    '------------------------------------------------------------
    
    'Citrix specific section
     
    if (Left(computerName, 4) = "zeus") then
     
    	computerName = LCase(WshShell.ExpandEnvironmentStrings("%CLIENTNAME%"))
     
    end if
    
    '------------------------------------------------------------
    
    
    
    'Begin install new printrs by machine name
    '--------------------------------------------
    
       
    
    Select Case room
          	
    
    
    
    	Case "ad2"
    
    Network.AddwindowsPrinterConnection "\\trigger\AD2_4100n"
    Network.SetDefaultPrinter "\\trigger\AD2_4100n"
    
    
    	Case "lib"
    
    Network.AddwindowsPrinterConnection "\\trigger\Ricohafi"
    Network.AddwindowsPrinterConnection "\\LIBOFF-001\DELL"
    Network.AddwindowsPrinterConnection "\\trigger\LRClaser"
    Network.SetDefaultPrinter "\\trigger\LRCLaser"
    
    	Case "lrc"
    
    Network.AddwindowsPrinterConnection "\\trigger\lrclaser"
    Network.SetDefaultPrinter "\\trigger\lrcLaser"
    
    	
    
    case else
     
    End Select
    
    
    'Clean Up Memory Used
    set WSHNetwork = Nothing
    set UserObj = Nothing
    set WSHNetwork = Nothing
    set DomainString = Nothing
    set WSHSHell = Nothing
    Set WSHPrinters = Nothing
    Set Network = Nothing
      
    'Quit the Script
    wscript.quit

  2. #2

    matt40k's Avatar
    Join Date
    Jun 2008
    Location
    Ipswich
    Posts
    4,427
    Thank Post
    368
    Thanked 642 Times in 524 Posts
    Rep Power
    159
    My two cent, (it's worth about that)

    The script looks good, looks like it might work, I've never used Citrix so I'm not sure about the API with regards to picking up client info, a quick Google found:

    Code:
    If CTXQuerySessionInformation("", WF_CURRENT_SESSION, WFClientName, Name)
    Not sure if that works, helps, whatever.

    Am I correct in thinking if you connect to the Citrix server you only want the local printers, in which case can't you add a script to (remove all printers,) add the local, set it to default, to the startup

    I'm prob talking rubbish.

  3. #3
    cookie_monster's Avatar
    Join Date
    May 2007
    Location
    Derbyshire
    Posts
    4,203
    Thank Post
    394
    Thanked 278 Times in 239 Posts
    Rep Power
    74
    The 'Citrix specific section is supposed to get the thin client units name and then add a network printer, you can't use the 'computerName' variable with thin clients like you do in Windows so you have to change that to 'clientname' and this seems to be the bit that isn't working.

    Code:
    'Citrix specific section
     
    if (Left(computerName, 4) = "zeus") then
     
    	computerName = LCase(WshShell.ExpandEnvironmentStrings("%CLIENTNAME%"))
     
    end if

  4. #4

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224
    Is your terminal server called zeus?

  5. #5

    matt40k's Avatar
    Join Date
    Jun 2008
    Location
    Ipswich
    Posts
    4,427
    Thank Post
    368
    Thanked 642 Times in 524 Posts
    Rep Power
    159

  6. #6
    cookie_monster's Avatar
    Join Date
    May 2007
    Location
    Derbyshire
    Posts
    4,203
    Thank Post
    394
    Thanked 278 Times in 239 Posts
    Rep Power
    74
    @ Geoff: Yes the TS is called zeus



    Matt i'll take a look at the link cheers.

  7. #7
    cookie_monster's Avatar
    Join Date
    May 2007
    Location
    Derbyshire
    Posts
    4,203
    Thank Post
    394
    Thanked 278 Times in 239 Posts
    Rep Power
    74
    I think judging by this page in the wiki that Ric might be the man with the answer.

    Printer Addition Based on Location

  8. #8

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,599
    Thank Post
    109
    Thanked 765 Times in 596 Posts
    Rep Power
    181
    You are looking at the script variable 'room' to allocate printers... this is set prior to the Citrix section so never gets updated to contain the the 'clientname' environment variable.

    Just edit the select statement to read:

    Code:
    Select Case left(computerName,3)

  9. Thanks to Ric_ from:

    cookie_monster (12th August 2008)

  10. #9
    cookie_monster's Avatar
    Join Date
    May 2007
    Location
    Derbyshire
    Posts
    4,203
    Thank Post
    394
    Thanked 278 Times in 239 Posts
    Rep Power
    74
    Ok don't flinch i'm back, i've simplified the script a bit and it still works on my fat clients but not on the TS still. This is a new Citrix setup is there something that i need to set for this to work? I've given the thin client device a hostname of lrc-001 and this shows up in the Citrix console as the client name, am i missing anything else?


    New Script

    It's basically giving me an 'object required' error on line 63 (computerName = LCase(WshShell.ExpandEnvironmentStrings("%CLIENTNA ME%")))

    Code:
    'Adds the appropriate network printer for the room
    
    
    Option Explicit
    
    'On error resume next
    
    Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Network, computerName, room, WSHPrinters, LOOP_COUNTER, Path
    
    
    Set objDomain = getObject("LDAP://rootDse")
    DomainString = objDomain.Get("dnsHostName")
    Set WSHNetwork = CreateObject("WScript.Network")
    Set Network = CreateObject("Wscript.Network") 
    computerName = LCase(WshNetwork.ComputerName)
    
    
    
    '-------------------------------------------------------------
    '-------------------------------------------------------------
    
    
    'Remove ALL old printers
    'Enumerate all printers first, after that you can select the printers you want by performing some string checks
    Set WSHPrinters = WSHNetwork.EnumPrinterConnections
    For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
    'To remove only networked printers use this If Statement
        If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
          WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
        End If
    'To remove all printers incuding LOCAL printers use this statement and comment out the If Statement above
    'WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
    Next
                                  
    
    'Give the PC time to disconnect old printers, wait 3000 milliseconds
    wscript.sleep 3000
    
    
    'Set local printer to default
    '------------------------------------------------------------
    
    Set WSHPrinters = WSHNetwork.EnumPrinterConnections
    For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
    'Find local printers
        If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) <> "\\" Then
          WSHNetwork.SetDefaultPrinter _              
                  (WSHPrinters.Item(LOOP_COUNTER +1))
        End If
    Next
    
    
    '------------------------------------------------------------
    
    'Citrix specific section
     
    if LCase(Left(computerName, 4) = "zeus") then
     
    	computerName = LCase(WshShell.ExpandEnvironmentStrings("%CLIENTNAME%"))
     
    end if
    
    '------------------------------------------------------------
    
    
       
    
    'Next line grabs the first 3 letters from the computername and adds the appropriate printer
    '-------------------------------------------------------------------------------------------
    
    Select Case (left(computerName, 3))
          	
    
    
    	Case "its"
    
    Network.AddwindowsPrinterConnection "\\trigger\Ricohafi"
    Network.AddwindowsPrinterConnection "\\trigger\IT_1320n"
    Network.SetDefaultPrinter "\\trigger\IT_1320n"
    
    	
    	Case "lrc"
    
    Network.AddwindowsPrinterConnection "\\trigger\lrclaser"
    Network.SetDefaultPrinter "\\trigger\lrcLaser"
    
    
    
    
    Case else
     
    End Select
    
    
    'Clean Up Memory Used
    set WSHNetwork = Nothing
    set UserObj = Nothing
    set WSHNetwork = Nothing
    set DomainString = Nothing
    set WSHSHell = Nothing
    Set WSHPrinters = Nothing
    Set Network = Nothing
      
    'Quit the Script
    wscript.quit
    Last edited by cookie_monster; 13th August 2008 at 10:16 AM.

  11. #10
    cookie_monster's Avatar
    Join Date
    May 2007
    Location
    Derbyshire
    Posts
    4,203
    Thank Post
    394
    Thanked 278 Times in 239 Posts
    Rep Power
    74
    Oops i was missing Set WSHShell = CreateObject("WScript.Shell") at the top of the stript so i had an empty object.


    I've used UCase rather than LCase as my whole production script has upper case hostnames and it seems to be working now, do you see any Citrix specific issues with this?

    Thanks for your help.

  12. #11

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,599
    Thank Post
    109
    Thanked 765 Times in 596 Posts
    Rep Power
    181
    Quote Originally Posted by cookie_monster View Post
    I've used UCase rather than LCase as my whole production script has upper case hostnames and it seems to be working now, do you see any Citrix specific issues with this?
    No... I just used lower case in mine because I did

  13. #12
    cookie_monster's Avatar
    Join Date
    May 2007
    Location
    Derbyshire
    Posts
    4,203
    Thank Post
    394
    Thanked 278 Times in 239 Posts
    Rep Power
    74
    Excellent cheers Ric.

    Grant.
    Last edited by cookie_monster; 13th August 2008 at 11:49 AM.

SHARE:
+ Post New Thread

Similar Threads

  1. Printers logon script error messages
    By indie in forum Windows
    Replies: 1
    Last Post: 14th September 2007, 11:34 AM
  2. Logon script & Printer script question.
    By Galway in forum Windows
    Replies: 3
    Last Post: 29th August 2007, 11:00 AM
  3. Terminal Server - limit which computers can be used to logon
    By broc in forum Thin Client and Virtual Machines
    Replies: 5
    Last Post: 26th June 2007, 02:21 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. Yet another Logon Script
    By ajbritton in forum Windows
    Replies: 3
    Last Post: 19th June 2006, 09:47 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
  •