+ Post New Thread
Results 1 to 8 of 8
Thin Client and Virtual Machines Thread, Mapping printers + terminal services in Technical; Hi All, I'm having a lot of trouble getting terminal services to map printers! Below is the script we're using ...
  1. #1
    tommej's Avatar
    Join Date
    Oct 2009
    Location
    Lincolnshire
    Posts
    727
    Thank Post
    39
    Thanked 150 Times in 108 Posts
    Rep Power
    81

    Mapping printers + terminal services

    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.

    Code:
    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?
    Last edited by tommej; 14th October 2011 at 03:35 PM.

  2. #2

    Join Date
    Jan 2007
    Location
    Nottinghamshire
    Posts
    530
    Thank Post
    1
    Thanked 84 Times in 58 Posts
    Rep Power
    38
    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
    Code:
    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

  3. #3

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,227
    Thank Post
    894
    Thanked 1,776 Times in 1,532 Posts
    Blog Entries
    12
    Rep Power
    461
    I have used this in the past, works well - Printer Addition Based on Location - Wiki

  4. #4


    Join Date
    Feb 2007
    Location
    Northamptonshire
    Posts
    4,697
    Thank Post
    352
    Thanked 803 Times in 718 Posts
    Rep Power
    348
    Hi Tommej,

    Are you using 2008R2 RDS?

  5. #5
    TheScarfedOne's Avatar
    Join Date
    Apr 2007
    Location
    Plymouth, Devon
    Posts
    1,161
    Thank Post
    705
    Thanked 172 Times in 156 Posts
    Blog Entries
    78
    Rep Power
    86
    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.

  6. #6
    tommej's Avatar
    Join Date
    Oct 2009
    Location
    Lincolnshire
    Posts
    727
    Thank Post
    39
    Thanked 150 Times in 108 Posts
    Rep Power
    81
    Quote Originally Posted by kmount View Post
    Hi Tommej,

    Are you using 2008R2 RDS?
    Just regular old 2008

  7. #7

    Join Date
    Jun 2009
    Location
    Poole
    Posts
    148
    Thank Post
    4
    Thanked 40 Times in 30 Posts
    Rep Power
    20
    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.

  8. #8
    tommej's Avatar
    Join Date
    Oct 2009
    Location
    Lincolnshire
    Posts
    727
    Thank Post
    39
    Thanked 150 Times in 108 Posts
    Rep Power
    81
    For now I think I have sorted this using powershell and the PSTerminalServices module

    Code:
    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")
    }

SHARE:
+ Post New Thread

Similar Threads

  1. Mapping Printers on Terminal Servers
    By FN-GM in forum Thin Client and Virtual Machines
    Replies: 6
    Last Post: 4th July 2011, 01:20 PM
  2. Mac Terminal Services
    By StuartC in forum Mac
    Replies: 5
    Last Post: 1st September 2009, 08:17 PM
  3. Terminal Services
    By faza in forum Windows
    Replies: 15
    Last Post: 1st June 2006, 10:37 AM
  4. Terminal Services +USB
    By Dos_Box in forum Windows
    Replies: 4
    Last Post: 25th May 2006, 01:26 PM
  5. Autograph on Terminal Services
    By Norphy in forum Thin Client and Virtual Machines
    Replies: 9
    Last Post: 12th May 2006, 11:53 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
  •