Monday, March 24, 2014

Dynamic RDP files for Thin Client sessions

This is horribly formatted. to be corrected later.


OK, So today's interesting task is to create multiple RDS conenction files based on a list stored on the server. We can then update this list as needed. Multiple conenctions will be created automagically on the thin client's public desktop at login.

There are many different thin and thick clients that will connect.
We don't know the resolution of each.
Some have two monitors, some don't
Some users like FULL screen, others like it windowed so they can see the client task bar and switch between sessions.
Not all monitors are the same resolution.

I'm sure there are more problems but the rest are social problems and not addressed in this context.

OK, so I violently attacked the internet with a barrage of search terms. looking for the quick and easy answer. Some reusable code that could be modified and used for my task at hand.

So the NEXT choice....yea, the search didn't go well. I do have to give credit to a number of sites with some good information. These are helping me on my way to an ultimate solution. See the bottom for the links.

So I started off by just editing the RDP files with notepad++ and changing the values. I got some great conenction files this way. Some variants were:
- RDP to an RDS Farm that uses load balancing, so you need to provide credentials first to that you only enter login info once.
- RDP to any server but go to the server FIRST so that you can authenticate at the server. Great for testing window settings and untimately for sysadmins who are too impatient to wait for the "securing remote conenction" to scroll for what seems like an eterninty.
- Windowed vs. full screen for each of these.

That was greeat. Boss loved it, should have stopped there taken the gold coin and moved on. nope.

I then found some code that created multiple RDS Connection files with powershell and a CSV File. I thought I was golden at that point. Now I could create these little gems and if later I wanted to add some, I could add it to the CSV File and BANG users would have new connections without having to reimage the stupid thin clients to add a single icon.

I got that working. Trimmed back on some features, added other features. Found out that some of the RDP options in the connection file have SPACES and others DO NOT. Very annoying.

So for my purposes I have three categories of settings in the file. 1) standard for all, 2) standard for this install, and 3) variable by conenction.

1) Standard for all
session bpp:i:32
connection type:i:2
disable wallpaper:i:1
allow font smoothing:i:0
allow desktop composition:i:0
disable full window drag:i:1
disable menu anims:i:1
disable themes:i:0
disable cursor setting:i:0
autoreconnection enabled:i:1
authentication level:i:2
prompt for credentials:i:0
negotiate security layer:i:1
alternate shell:s:
shell working directory:s:
use redirection server name:i:0

2) Standard for this install
NOTES: We wanted the connection bar to be available, but not pinned, and we wanted ALL Windows shortcut keys to go to the remote sessions. That way you could use ALT-TAB in a windowed session or a full screen session.

3) Variable by connection
screen mode id:i:2
full address:s:server-farm
NOTES: For these, the screen mode id HAS SPACES IN IT. Don't forget that it can be frustrating. and a 2 is full screen 1 is windowed.
Desktop height and width are the dimentions of the remote session, NOT the window that is created. More on that later.
WinPosStr is a funky option but can vary based on session.
full address - this hard codes the server into the conenction easy for users to click and connect.
username - so there is also a Domain option, but I couldn't get it to work. If you have a set of thin clients that are on a workgroup conecting to domain servers, you want to make it easy for the users to default the domain to the domain of the server you are conencting to. Just put the domain and the backslash in there and you are good to go. Since I'm using a csv file I put the backslash in in the code, not in teh CSV file.
enablecredsspsupport - 1 says "Get my credentials now.", 0 says "Connect me as fast as possible and I'll authenticate when I get there." 1 is good for RDS 2008/2012 farms with load balancing. 0 is great for sysadmins and impatient people.

so, most of these variables are easy to set. I created a CSV File that had:
Server, ServerName, Resolution, Login, Domain
server-farm, Accounting, Full, Farm, conteso-acct
server-farm, Accounting, Window, Farm, conteso-acct
DC-001, Domain Ctlr 1, Full, Single, conteso-admin
DC-002, Domain Ctlr 2, Full, Single, conteso-admin
, RDP Full, Full, Single,
, RDP Window, Window, Single,

the last two are for admins that don't know where they are going, but need some basic settings ready to go. They know the server and the domain they are connecting to and just want to choose windowed or full screen. The rest should be fairly obvious, feel free to comment if they aren't and I'll make some notes.

So now I can read in a file, create the RDS Conenction files, and update it without reimaging the thin clients.

Code for this is here:

Now came the tough part. For the windowed sessions I have to maximize the area. RDP will not let you resize the session once you are connected, that's why you pay Citrix $300+ per user for XenDesktop. With that, you can resize on the fly. Yay for you. I'll go buy desktops instead, it's cheaper.

SIDENOTE: Have you seen the new Intel Nuc It's smaller than the Wyse Thin Clients and works great!!

So when I needed to dynamically size the windowed sessions, I needed to get the available size of the screen Minus the taskbar and any window borders. I found a site with some window size collection info. That got me on the WMI Win32 path. So I created this section.

$rdpW = 0
$rdpH = 3000
foreach ($desktop in $desktops) {
if ($rdpH -gt $desktop.ScreenHeight) { $rdpH = $desktop.ScreenHeight }
$rdpW += $desktop.ScreenWidth
[int]$rdpH *= .93
[int]$rdpW *= .98

I resized the window to be less than the width and height to fit without scroll bars.

winposstr:s:0,3,0,0,800,600 <<--- data-blogger-escaped-5000="" data-blogger-escaped-absolute="" data-blogger-escaped-and="" data-blogger-escaped-as="" data-blogger-escaped-bottom="" data-blogger-escaped-br="" data-blogger-escaped-can="" data-blogger-escaped-coordinates.="" data-blogger-escaped-far="" data-blogger-escaped-huge="" data-blogger-escaped-i="" data-blogger-escaped-if="" data-blogger-escaped-in="" data-blogger-escaped-left="" data-blogger-escaped-like="" data-blogger-escaped-of="" data-blogger-escaped-really="" data-blogger-escaped-right="" data-blogger-escaped-set="" data-blogger-escaped-so="" data-blogger-escaped-something="" data-blogger-escaped-tell="" data-blogger-escaped-the="" data-blogger-escaped-this="" data-blogger-escaped-to="" data-blogger-escaped-top="" data-blogger-escaped-window="" data-blogger-escaped-you="">
LINKS - mainly a rabit hole. I got distracted and started to learn too much about WMI calls.

No comments:

Post a Comment