1

I am trying to figure out this Problem: When a user disconnects his/her RDS (on Windows Server 2012 R2) session in Office 1 and reconnects in Office 2, then still all the Printers relevant to Office 1 will be mapped.

First idea was to use the Task Scheduler to run a powershell script on trigger "Session reconnect" which Looks into the "clientname" variable and adds all relevant Printers to that Location after the reconnect.

Problems with this are that:

  • to make the script run in the context of the specific user that just reconnected and not in some administrative context (tried solving this with run as Group DOMAIN\Users, but seems to work not as desired)
  • the "clientname" Environment variable is not available when the PS script is run via Task Scheduler. It seems it is the only variable missing, but, bad enough, thats exactly the one i would Need here!

So, I am either looking for a way how the Scripting Problem could be solved properly or, even better, is there a known best practice how to handle Printer mapping when a user reconnects a terminal Server session from a different Location? Doesn't make much sense to have the paper appear in Offices/Locations far away ;-)

Thanks very much.

1 Answer 1

0

Unfortunately I think your best bet here is to have a script that the user can run themselves when they reconnect.

There are several things that make it difficult for you to have something do this automatically (some you've already seen):

  1. ClientName is a User level environment variable (it's different for each user on the RDS server).
  2. A scheduled task won't have access to the User level environment variables (except maybe for a specific user it's set to run as).
  3. A scheduled task set to run at user logon would work if the users were logging on, but won't be triggered by a reconnect (if the users were logging on, you wouldn't have this problem in the first place).
  4. Any process that would be started in the user context (like if you had a PowerShell script that ran on logon and checked periodically) gets a copy of the environment on startup, and it wouldn't see a change in ClientName on a reconnect unless the process was restarted. Spawning a new process wouldn't help either because the child process would inherit a copy of its parent's environment.
1
  • thanks this is what I was afraid would not work out. As you said, a manually triggered script link on the desktop would need to be introduced then...
    – schueric
    May 29, 2015 at 8:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .