Skip to main content

getting default printer from registry

  • May 11, 2021
  • 2 replies
  • 2 views

Forum|alt.badge.img

Hello

Im'using this instruction for getting the default printer

pDefaultPrinter = $setting("", "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\Device", "REGDATA")

The user  connect in TSE without the "local resources"  setup for printer

I just implement the connexion with  this option  and my problem  is that the $settings returns me the name of

printer wich is in use when this option is not set up 

instead of the printer name I intend to get :   HPxxxx (redirection of x)

(I hope this is clear)


2 replies

Iain Sharp
Forum|alt.badge.img+5
  • Inspiring
  • May 11, 2021

Hello

Im'using this instruction for getting the default printer

pDefaultPrinter = $setting("", "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\Device", "REGDATA")

The user  connect in TSE without the "local resources"  setup for printer

I just implement the connexion with  this option  and my problem  is that the $settings returns me the name of

printer wich is in use when this option is not set up 

instead of the printer name I intend to get :   HPxxxx (redirection of x)

(I hope this is clear)


A google indicates there may be another registry setting for terminal services session default printers. 


The registry key used for local or network printers is:

HKEY_CURRENT_USER\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\Device

The registry key used for redirect printers is:

HKEY_CURRENT_USER\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\SessionDefaultDevices\\ "session" \\Device


I think you can get the 'session' part of this by looking at the environment variable 'sessionname' (using $setting?) 

Regards, 

Iain


Forum|alt.badge.img

Hello

Im'using this instruction for getting the default printer

pDefaultPrinter = $setting("", "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\Device", "REGDATA")

The user  connect in TSE without the "local resources"  setup for printer

I just implement the connexion with  this option  and my problem  is that the $settings returns me the name of

printer wich is in use when this option is not set up 

instead of the printer name I intend to get :   HPxxxx (redirection of x)

(I hope this is clear)


It looks like this key is in windows server 2012, not with 2016 and present again in 2019

currently I need it in 2012 and 2019 (lucky)

so how do I use $setting to get the session name ?

I'm using  Query Session / Qwinsta to get the session name  and it gives me :

rdp-tcp#128   and in the register I got   : S-1-5-5-0-2612842709