Discussion Locked

User Variables and Scripts

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

What is the easiest way to set user variables using a login script. These variables only need to be present for certain users on these NT 4.0 clients. I have tried a generic 'set' command in the script, but to no avail.

We currently use login scripts, and I would like to be able to just add a few more lines and have the job done!

Thanks in advance.

8 replies

by caddy

I've used set x=y, where x is name of your variable and y is the result. For example, set test=hi would return "hi" if i typed in echo %test% at a cmd prompt. Then, create a group for the users that you want to run the variable. Use the ifmember in the script to identify the group. You would need to either run ifmember from the netlogon share or copy if to the machines systemroot.

if exist %systemroot%\system32\ifmember.exe goto skip
copy %logonserver%\netlogon\ifmember.exe %systemroot%\system32 /Y /V
:skip
ifmember "groupname" goto var
goto end
:var
set x=y
:skip
:end

by dutchman10

Thank you, but I should clarify.
I have the specific group I want set up in User Manager. I just point the user to the script file through the Profile tab in User Manager.
I have the 'set' (x=y) command in the script that the user then executes when they log-on. However, the user variable is not set after the user logs in. Is there a way to have this log-in script set the variable, or do I have to go to more lengthy measures?

by /dev/null

When setting variables using the 'set' command, they are only valid for that command interpreter session. In other words, assigning variables in the login script (batch, cmd file) using the standard 'set' command doesn't work. They only exist in memory until the login script finishes (exits the command interpreter).

If you want the variables to be permanent, available in the shell or command interpreter session after the login script, you need to use a separate command. I've used the setx.exe utility from the resource kit in the past to assign user and machine(system) variables via the login script. There are probably other utils out there as well. Setx.exe is from the Resource kit(both NT4 and W2K). Here's a link to it: (remove spaces in URL, if any appear)
http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/setx-o.asp

System variables are available to any user or process logged into the machine. User variables are only available when that particular user is logged on.

One other note: User and System variables are written to the registry. If you have any registry editing tools or programming experience you can edit either one of the following reg-keys to add, delete, modify variables:

user variables:
HKCU\Environment

system variables:
HKLM\System\CurrentControlSet\Control\Session Manager\Environment

I believe these reg paths are true for both NT and W2K.

Good luck!

by /dev/null

The URL: remove the space between 'too' and 'ls' in /tools/ section of the URL for a working link.

by mckaytech

Your approach should work so I'm wondering if there is a permissions issue or something like not replicating the edited script to the LOGON directory.

As a general rule, anything that works from the command line should work in a login script. Have you verified that your set command works from the command line and has the intended result?

regards!

paul

by dutchman10

I thought it would work too! But it would not take the variable.
If I issue a set command from a command line, it will work, untill I close the command interpreter.
Thanks

This discussion is closed to new replies.