Sreedhar GS
Sreedhar GS

Reputation: 2788

How to persist windows environmental user variable across the sessions in windows

I have a requirement where in which,

Lets say

  1. Am logging with a user called AAA to my windows machine and execute below command SETX home %UserProfile%

This will set home= C:\Users\AAAand same we can see in env variables.

  1. I will logout and log in with user BBB if i make echo %home%, this user will not have home env, i wish to get home=C:\Users\BBB here also without using SETXagain.

Please suggest me the solution, How to set one user variable that should persist across any user he login to machine.

Note: It should not be system variable.

Please share your thoughts.

Upvotes: 0

Views: 290

Answers (2)

cjfester
cjfester

Reputation: 1

A bit too late, but for anyone searching ... "home" is not a "native" variable for windows, then, you must set it. In the thread the user maked it by SETX home=%UserProfile%

SETX make it "public" for other sessions/programs that will use it. NOT FOR other user.

That said, each user must set this variable at logon (or other point before run programs that use it). The simplest way i found is: Task Scheduler -> new task -> trigering/event [AT USER LOGIN] -> command/program: SETX home=%UserProfile%

I not sure if it works if the user is not an administrator. Workaround:

  1. use just the SET command;
  2. export a .reg key with this setting at system/administrator level and import it at each user login;
  3. one time user root/system/administrator make it in the registry, it will be available to all users ever and will not necessary make other scripts or schedule at login.

Upvotes: 0

Loïc MICHEL
Loïc MICHEL

Reputation: 26150

Whitout being a system (machine) variable, the environment variable is a per user setting (store in HKCU in the registry), it won't be accessible by another user.

Upvotes: 3

Related Questions