Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printer login script with Citrix

Status
Not open for further replies.

porkchopexpress

IS-IT--Management
May 26, 2005
3,996
GB
I have cross posted this as i'm not sure if it's a problem with Citrix or my VB script. The script runs and adds printers to windows clients but won't add any when logging onto the Citrix/TS box, i think the problem lies in the "'Citrix specific section". Can anyone see if there is an issue with the code?

Thanks.


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
 
Right I’ve sorted it here is the working script in case anyone is interested, it ordinarily grabs %computername% and then maps a printer this is obviously an issue on a Citrix box so is i picks up the Citrix server name it replaces it with the %clientname% variable so you can add a location specific printer. For this to work correctly your TS clients need to have location specific names.


Code:
'Adds the appropriate network printer for the location

Option Explicit

On error resume next

Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Network, computerName, room, WSHPrinters, LOOP_COUNTER, Path


Set WSHShell = CreateObject("WScript.Shell")
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
Set WSHNetwork = CreateObject("WScript.Network")
Set Network = CreateObject("Wscript.Network") 
computerName = UCase(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


'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 UCase(Left(computerName, 4) = "ZEUS") then
 
	computerName = UCase(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 "\\server\Ricohafi"
Network.AddwindowsPrinterConnection "\\server\IT_1320n"
Network.SetDefaultPrinter "\\server\IT_1320n"

	
	Case "LRC"

Network.AddwindowsPrinterConnection "\\server\lrclaser"
Network.SetDefaultPrinter "\\server\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
 
Take a look at my FAQ.the script works on the premis that the use names are prefixed with a 3 digit number for "branch/department" the script peels the prefix out and connect to all printers with sharenames prefixed with the same 3 digits.  If the user name does not have a 3 digit prefix it then prompts for the branch/department number.  I also have a matching script that uses AD security group memberships to set default printers if your interested.

Thanks

John Fuhrman
Titan Global Services
faq329-6766
 
Thanks for the offer John i'll take a look as it might come in handy in certain situations, unfortunatly as we are a college our users move from location to location so our printers really need to be mapped on the device location rather than the users location.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top