Jump to content

Recommended Posts

Posted (edited)

Hi All, I'm having a lot of trouble getting terminal services to map printers!

 

Below is the script we're using along with some debug stuff which was supposed to help us.

 

Dim LeftString, netPrinter
Set Sh = CreateObject("WScript.Shell")
sys = Sh.ExpandEnvironmentStrings("%CLIENTNAME%")
LeftString = Left(sys, 3)
if leftstring = "HP0" OR leftString = "IEC" then
Set netPrinter = CreateObject("WScript.Network")
netPrinter.AddWindowsPrinterConnection "\\printserver\printer"
netPrinter.SetDefaultPrinter("\\printserver\printer")

else
wscript.echo "Debug, client name: " & sys
end if

 

Now the problem occurs when we use the script fro GPO as a login script. Upon login I get a popup with "Debug, Client name: %clientname%".

 

BUT! If I run the script manually, from an interactive session, it behaves as expected by either mapping the printer, or giving the debug message displaying the clientname correctly.

 

Any ideas?

Edited by tommej
Posted

Maybe the variable doesn't exist at that point, can you get a list of environment variables and see?

 

I wanted to map printers due to IP, so used GETTSCIP.exe and


Set WshShell = wscript.CreateObject("WScript.Shell")
Set oExec = WshShell.exec("gettscip.exe")
sOutput = oExec.StdOut.ReadLine
sOutput = Mid(sOutput, 19, len(sOutput)-18)
iparray = split(sOutput,".")
 location =  CInt(iparray(2))
 
 select case location
  case 58
   base = "a"
  case 59
   base = "b"
  case 60
   base = "c"
  case 61
   base = "d"
  case else
   base = CStr(location)
 end select
 GetTSCIP = base
End Function

Posted
Im going to do a blog post on Printer Mapping with RDS - as Ive just completed a bit project with it. Learnt a hell of a lot, and its taken 3 weeks to get it right. Will update this when I post it.
Posted
You can use group policy preferences with terminal services targeting to deploy printers to specific TS clientnames. I use this for 2008 R2 but it required a hotfix before it would work.
Posted

For now I think I have sorted this using powershell and the PSTerminalServices module

 

Import-Module PSTerminalServices

$result = Get-TSSession -Filter {$_.Username -like [Environment]::Username} | Select-Object ClientName -expandproperty ClientName
$printServer = "\\printerserver\"

if ($result.contains('IEC')) {
$printer = New-Object -ComObject WScript.Network
$printer.AddWindowsPrinterConnection($printServer + "printername")
$printer.SetDefaultPrinter($printServer + "printername")
}

if ($result.contains('HP0')) {
$printer = New-Object -ComObject WScript.Network
$printer.AddWindowsPrinterConnection($printServer + "printername")
$printer.SetDefaultPrinter($printServer + "printername")
}

if ($result.contains('whatever')) {
$printer = New-Object -ComObject WScript.Network
$printer.AddWindowsPrinterConnection($printServer + "printername")
$printer.SetDefaultPrinter($printServer + "printername")
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



  • 33 When would you like EduGeek EDIT 2025 to be held?

    1. 1. Select a time period you can attend


      • I can make it in June\July
      • I can make it in August\Sept
      • Other time period. Comment below
      • Either time

×
×
  • Create New...