I manage a terminal server in our production environment that serves many different machines that connect under the same generic ID. Using the Cassia library, I am easily able to capture everything I need to know about the remote connections programmatically, but I am as of yet stumped as to how I need to go about applying the printer change to that user. My distinguishing criteria will be the name of the PC that s/he is connecting from. There are 4 machines in particular that I am interested in, and the rest will be ignored.
In a nutshell, I need to capture when these particular PCs log on, and set a default printer for them for the remainder of their session.
At a local level, it is no challenge to change a default printer programmatically. I seem to be struggling with changing the default printer for a user's session on a remote terminal server from another utility server.
The easiest way to do this is create a script that is set to run on login and set the printer via a WMI to
Win32_Printer.SetDefaultPrinter
.Here is a example of how to do it in a simple 3 line powershell script
Save that in a
.ps1
file and set the terminal server policies to run the script on login.If you don't want to use a fixed name in the script it is easily modifiable to query some other external source, just replace
'Name Of Printer To Use'
with a variable that holds the name you want to connect to.The
SetDefaultPrinter
method is supported on Windows Vista/Server 2003 and up.