• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 487
  • Last Modified:

machine login script for each user

Hello,

We're running Terminal Services on Windows 2003 Std.  I have an application that requires an environment variable "station" to be set to a 2 or 3 digit number for tracking.  I need some way to run "setx ##" for each user that logs on to the terminal server and have the ## be different for each.

How can this be done?
0
wylde342
Asked:
wylde342
  • 5
  • 4
  • 3
1 Solution
 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
That's no problem at all Server 2003 TS has this capability natively.  Please see the "Editing User-Specific Logon Information" seciton in this TechNet article:  http://technet2.microsoft.com/WindowsServer/en/Library/6caf87bf-3d70-4801-9485-87e9ec3df0171033.mspx

Jeff
TechSoEasy
0
 
Rob WilliamsCommented:
try:
 set x=%sessionname:~8,9%
Should equal a 2 digit unique number

Sessionname is a default variable assigned to the session. Usually  returns  RDP-tcp#**  with ** being the session number. The :~8,9  will return only the last 2 (8th - 9th) characters
0
 
wylde342Author Commented:
Tech - how would you set the usrlogon.cmd on a per user basis?  Again, I need to set this variable to a different # for each user when they login.  Could I use something like "If user x, set x station ##?"  Please forgive my lack of terminology, I suck with programming.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
As I was looking for some example code to give you for this, I was thinking that if this is an application that has sold more than two or three copies, I am sure they would have addressed this issue already.  What I've seen is that when a unique station number must be assigned to a user, that information is kept in an .ini file within the application's folder.

I don't know if this is the application you are trying to use, but as you can see by their Terminal Server instructions, this is how it's handled:  http://www.legalmaster.com/lm04011.htm

I would suggest that you contact the software manufacturer or look at their support site to determine the appropriate method for that particular program.  Because if it does read an .ini file when a user logs on you definitely want to go that route.

Jeff
TechSoEasy
0
 
Rob WilliamsCommented:
The :
set station should work fine for you if you add it to the AutoExcec.nt file in  C:\Windows\System32\AUTOEXEC.NT
We have a couple of older applications that require a station 'name' and accomplish it with the command in that application.
To test the output, at a command line enter:
echo %sessionname:~8,9%

0
 
wylde342Author Commented:
Thanks for the tip; but again, how can I run this on a per user basis?  Each instance needs to have it's own "setx" variable assigned.
0
 
Rob WilliamsCommented:
>>"how can I run this on a per user basis?  "
Sorry overlooking the fact that this is a TS session. You could not use AutoExec.nt, however, I believe adding it to the users logon script, it should remain native to the session similar to the tmp, username, etc. variables. I cannot test here right now.
0
 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
I'd agree with RobWill's concept but instead you would put that in batch file and then designate that batch file to run as the login script which is configured on the "Profile" tab of the user's properties.  

So, then the question would be... what is the exact syntax for the statement in the batch file.

I think you didn't understand that RobWill's use of "Set" instead of "Setx" should be just fine... they both do the same thing, it's just a syntax difference...
The overview of setx is here:  http://snipurl.com/q5em

So... the absolute SIMPLEST way would be to have users all logon with a username that = a two digit number.
Then a batch file which had this command line would work:

setx station %username%

Otherwise you would have to create a different variable that calls on a predefined list based on the user's name.  (this is what the legalmaster example above does).

RobWill... I don't think your formula will work because it would require that the session name have two numerical digits... and the first 9 session names only use a single digit number (ie, RDP-Tcp#6)  I don't know how you would change that parameter.

If you had just a few users, you could create a separate batch file for each one and designate that particular one as their login script, so you would have the following:


User: John
Login script (on John's Profile tab): 01.bat
Contents of 01.bat:  setx station 01

I'm sure there are ways to script the variable to check against an "in-use" table... but since this is a maximum two digit number I'm assuming you have less than 99 users... and it would take you less effort to just do this manually for now.

Jeff
TechSoEasy




0
 
Rob WilliamsCommented:
Hi Jeff, I tried the variable on a couple of TS's when I was the only user, so I assumed it was always 2 digit, however.....never assume.
I did however try using set=%sessionname:~8,10%  looking for 3 digit and it returned only the two. That simply proves you wouldn't get an error if less than the requested number of digits.
If necessary to have 2 or 3 digits, I could modify to always have a false first digit. However, I like Jeff's idea of modifying each user's logon script to have a unique ID number. Would be a consistent #, better for troubleshooting/tracking, and less of a risk of failure. However, I can appreciate if you have dozens of users you don't want to have to create a different logon script for each.
0
 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
Just an FYI to wylde342,
The difference in using set vs setx is that you need an "=" between the command and the variable.  Otherwise they do the same thing.

Rob... I was thinking you could change the name of the RDP session (which is possible) but it will stick the "#" in there no matter what.

Jeff
TechSoEasy
0
 
wylde342Author Commented:
Jeff, Tech

I'm giving you the points for the amount of work you did.  However, I did figure it out a different way and it's detailed below.  Yeah, it was a bit of a pain to setup, and it's quite manual, but it works exactly how I wanted.  Plus, I figured it out myself (with tips from EE) which is always key for the future.

C:\windows\system32\usrlogon.cmd has a "Call c:\windows\system32\users.cmd"

users.cmd

@echo off
IF "%username%" == "user1" goto user1
IF "%username%" == "user2" goto user2
(etc up to 25)

:user1
setx station 50
exit

:user2
setx station 51
exit

(etc, etc)
0
 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
Oh, that's brilliant!  If you (or I, or Rob) were a bit more skilled in scripting, I know you could have used a formula instead of the manual format.  In fact you may want to post that over to the http:VB_DOT_NET TA as well as the http:Visual_Basic TA because there are a number of scripting folks over there that may be able to tune it up for you.  Because I think to have it parse that more manual instruction may slow things down a millisecond or two.  :-)

You also could send it to the Microsoft Scripting Guy to see if there's a better way... because now that you have this actually working and in writing, it's much easier to understand what you are trying to do and I'm sure that someone can come up with the "best" way.

Hey, Scripting guy! http://www.microsoft.com/technet/scriptcenter/resources/qanda/default.mspx

Jeff
TechSoEasy
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now