Tutorial :Enumerate printers for a specific Terminal Server session


I am looking for a way to see what printers a specific user has mapped into his or her TS session.

How can I achieve this with WMI (via PowerShell) or VB-Script? Is there a built-in way I'm not aware of?

EDIT: In our construct mapping of local printers by the RDP-Client is disabled. Users get their printers created during login via VBS-Script and deleted during logoff.

So there's no printers installed directly on our TS server and querying the Win32_Printers WMI class returns nothing. The printers are installed on a dedicated print server. Querying the printers on that server returns ALL printers and not the one mapped for a single user.


Thanks to Remko's comment I was put into the right direction and finally made a script that did what I needed.

Basically the script determines the SID of the user and looks in the user's registry hive (HKEY_USERS\$sid\Printers\Connections) for the created printers.

Here's the quick and dirty powershell script:

$server = 'servername'  $userName = 'username'    $regHKLM = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $server)  $regProfileList = $regHKLM.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")    foreach ($sid in $regProfileList.GetSubKeyNames())  {      $profileImagePath = $regProfileList.OpenSubKey($sid).GetValue("ProfileImagePath")      if ($profileImagePath.EndsWith("\$userName"))      {          $regHKU = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("Users", $server)          $regUser = $regHKU.OpenSubKey("$sid\Printers\Connections")          foreach ($printer in $regUser.GetSubKeyNames())          {              $printer.Replace(",", "\")  # backslashes are replaced with commas, revert that          }      }  }  


I can't check in a TS session right now, but this does it normally in powershell:

Get-WMIObject Win32_Printer


From here: http://www.microsoft.com/technet/scriptcenter/guide/sas_prn_tart.mspx?mfr=true

strComputer = "."  Set objWMIService = GetObject("winmgmts:" _   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")  Set colInstalledPrinters = objWMIService.ExecQuery _   ("SELECT * FROM Win32_Printer")  For Each objPrinter in colInstalledPrinters   Wscript.Echo "Name: " & objPrinter.Name   Wscript.Echo "Location: " & objPrinter.Location  Next  


May be You need CUPS based tecnology? It's simple task for cups on any unix but I'm not sure about Windows.


This did the trick for me unlick seanyboy answer which returns the local printers this script return the network printers a users is connected to, works fine on a Terminal Server \ Citrix session



As far as I understand You can read some field in Registry.

PS: I prefer to use Linux for terminal service ;)

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »