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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Environment Variables Via GPO

Status
Not open for further replies.

mrclasik

Technical User
Dec 16, 2004
18
US
Is there a way to set Environment Variables Via GPO. Say for instance, I want to define a path: \\server\packages. is it possible to push that out. Maybe scripts? Any help would be appreciated.
 
Here you go. This script will add to the Path environmental variable whatever you set NewPath to be equal to.

Code:
Set objShell = WScript.CreateObject("WScript.Shell")
Set colUsrEnvVars = objShell.Environment("USER")

NewPath = "C:\MyNewPath"

colUsrEnvVars("PATH") = colUsrEnvVars("PATH") & ";" & NewPath
Wscript.Echo colUsrEnvVars("PATH")

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Hey Mark, I believe this is what I need. I have tried to implement it, but failed. I put it in sysvol under scripts, and have set it to run in GPO, yet when you log on it shows the path but does not apply. Am I doing something wrong.

Thanks for your help.
 
Set it as a login script. Put the code in a text file and give it a .VBS extension.

In your GPO go to:

User Configuration
Windows Settings
Scripts
Login Scripts

Double click login scripts. Click View Files. Paste the vbs file in that location and then close that explorer window. You should be back at where you clicked View Files. Now click Add. Pick the vbs file and click OK.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
How can the script be reversed? I'd like to create a few paths to run an app then have another script to remove the added paths.

Thanks!
-Steve
 
Code:
Set objShell = WScript.CreateObject("WScript.Shell")
Set colUsrEnvVars = objShell.Environment("USER")

oldPath = colUsrEnvVars("PATH")

NewPath = "C:\MyNewPath"

'Append the new path info
colUsrEnvVars("PATH") = colUsrEnvVars("PATH") & ";" & NewPath
Wscript.Echo colUsrEnvVars("PATH")

'Now reset it back to the old path
colUsrEnvVars("PATH") = oldPath
Wscript.Echo colUsrEnvVars("PATH")

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top