Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use a GPO to set environment variable 1

Status
Not open for further replies.

tvbruwae

Programmer
Aug 9, 2001
224
EU
Hi

We would like to set a user or system variable on all computers in our domain. Can this be done through group policies? I.e. can we define a name and value for an environment variable with a GPO?

Thanks,
Tim
 
I've not checked this works, if it doesn't check spelling mistakes. sorry, I'm a bad typer.

This is a solution that requires some alterations in the ADM files.

This is an ADM file I have created. You will need to edit something in this everytime you want to add a new env variable, however, if you want to change the path of one you have already added, you just use the normal GPOE.

Copy and Save
FILENAME C:\Windows\inf\NJCISEditds.adm

Code:
CLASS MACHINE
CATEGORY !!NJCIS
  CATEGORY !!EnvVars
    POLICY !!SetEnvVars
      KEYNAME "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
      EXPLAIN !!exSetEnvVars
      PART "ExampleVariable" EDITTEXT
        VALUENAME "ExampleVariable"
      END PART
    END POLICY
  END CATEGORY
END CATEGORY

[strings]
NJCIS="NJC Info Sys GPEdits"
EnvVars="Environment Variables"
SetEnvVars="Set Environment Variables"
exSetEnvVars="To add an environment variable. Open C:\Windows\inf\NJCISEdits.adm. For each variable you want to create. Copy and paste, in sucession from and including PART to END PART. Within the quotations of VALUENAME, enter the name of the variable you wish to create. The path to associate with this variable is set using the text box in the GPO setting. \n\n WARNING \nThis is not a TRUE POLICY SETTING. Any changes made with this setting configuration will remain on that computer untill manually removed."

You will need to import this into your COMPUTER SETTINGS > ADMINISTRATIVE TEMPLATES > right click > Add/Remove Templates > Add > Select c:\windows\inf\NJCISEdits.adm > Close.

To see this setting you need to disable Fully Managed only viewing.

View > Filtering > UNcheck (remove) "Only show policy settings that can be fully managed"

Under Computer Settings\Administrative Templates you should now see a folder called "NJC Info Sys Edits", under that you should see a folder called "Environment Variables", in there you will see a setting, marked with a red dot, called "Set Environment Variables"


To add an environment variable. Open C:\Windows\inf\NJCISEdits.adm. For each variable you want to create. Copy and paste, in sucession from and including PART to END PART. Within the quotations of VALUENAME, enter the name of the variable you wish to create. The path to associate with this variable is set using the text box in the GPO setting. so if you want to configure two variables called ExVarMy1 and ExVarYour2 the middle of the ADM file should look like this

Code:
      PART "ExVarMy1" EDITTEXT
        VALUENAME "ExVarMy1"
      END PART
      PART "ExVarYour2" EDITTEXT
        VALUENAME "ExVarYour2"
      END PART

Does that make sense. Let me know if you need any clarification


Hope this Helps.

Neil J Cotton
njc Information Systems
Systems Consultant
 
BTW

I tested my above template code, and it works perfectly.


BIG REMEMBER
============
Turn off Fully Managed Policy viewing, otherwise you will see the folders, but wont see the setting.

Hope this Helps.

Neil J Cotton
njc Information Systems
Systems Consultant
 
And Just for clarification purposes.

I have used the same text in both

PART and VALUENAME

PART text is just the text you see on the setting interface next to the box.

VALUENAME is actually the name of the EnvVar that will be the created. The above example will present you with an interface that looks like this
ExampleVarMy1 _____________________

ExampleVarYour1 _____________________

but for a more intuitive interface you could use this code

Code:
      PART "ExVarMy1 variable path  " EDITTEXT
        VALUENAME "ExVarMy1"
      END PART
      PART "ExVarYour2 variable path" EDITTEXT
        VALUENAME "ExVarYour2"
      END PART

which would give you

ExVarMy1 variable path __________________

ExVarYour1 variable path __________________


Hope this Helps.

Neil J Cotton
njc Information Systems
Systems Consultant
 
Hi ncotton

I tried your adm template with the required adjustments and it works perfectly! Thank you for the quick and detailed answer!
 
Thats what I'm here for! :) [Coiy grin (sp)]

Don't thank me...pay me...you know how. You have the account number.

I accept payment, in Cash, Bank Transfer, Forum Votes, Musical Instruments, Squirel Pelt and Sofa Cleaner...and at a push....cheques.

Hope this Helps.

Neil J Cotton
njc Information Systems
Systems Consultant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top