Jump to content

Is it possible to add system variables via script?


ceez

Recommended Posts

zup peeps,

at work we have an application that we install which doesnt add system variables to windows. We then have to go and add about 10 variables manually...this is time consuming, tidious, and if you mess up you'll start getting a bunch of error messages.......not to mention that application is buggy as hell! :-/

So I was wondering if there's a script, batch, ANYTHING in which we can just type down the variables and values in a file, run it, and that's it...everything is entered in the variables.

If you can help you would really help me out! :thumbup

thkz

Ceez

Link to comment
Share on other sites


MCT, i've been digging around the reg and then you come up with a simple answer....SET command!!! :) go figure....

I have a Q, I added a TEST environment i typed set add=test. when i type SET from the cmd prompt it shows a bunch of variables....the one's that ARE listed under the environmental settings in windows under SYSTEM PROPERTIES and some that dont. The one that I added via the SET command doesnt physically appear on that properties window. Is there a way that I can make it appear? It would help because people usually go there to check the environments when something is not running right...if they dont see the environments they will freak out, amaze at the fact that the application has been running and then add them manually via SYSTEM PROPERTIES-environment variables button.

I was able to find some stuff out from the registry.

The following 2 paths in the registry show the environment variables listed in windows

hklm\system\controlset002\control\session manager\environment

hklm\system\currentcontrolset\control\session manager\environment

If i add a string value to any of the two, it will reflect on the other and also in the system properties.

AND

The following 2 path also show the environments but whatever i add here will not copy to the other path NOR will it show in the system properties

hklm\system\controlset001\control\session manager\environment

hklm\system\controlset003\control\session manager\environment

would it be better to add it via registry entry? or is there a way for the SET cmd to visually add it to system properties????

thkz a million! :thumbup

ceez

Link to comment
Share on other sites

ok let me show you guys (whomever is reading this post! :)) the variables that I need to add to the registry

"BRD_ROOT"="G:"
"BRD_SILDIR"="G:\SIL"
"PLB_PATH"="G:\;G:\PROGRAMS;G:\DATA;G:\COMMANDS"
"PLB_SYSTEM"="G:\COMMANDS"
"PLB_TERM"="ANSI"
"PLBWIN_ICON"="G:\BRD.ICO"

this is the .reg file that I created:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
"BRD_ROOT"="G:"
"BRD_SILDIR"="G:\SIL"
"PLB_PATH"="G:\;G:\PROGRAMS;G:\DATA;G:\COMMANDS"
"PLB_SYSTEM"="G:\COMMANDS"
"PLB_TERM"="ANSI"
"PLBWIN_ICON"="G:\BRD.ICO"

When I save it and run it, the only variables showing are BRD_ROOT & PLB_TERM...what gives? am I writing this .reg file incorrectly??? I even placed them in alphabetical order!! :P

I also need to add "G:\COMMANDS" to the Path variable that is already in the system. How would I add that one?

"PATH"="G:\COMMANDS"??? wouldnt that erase all the info that is currently in the Path variable and insert the g:\command one?? oh so confused!!!! :blink:

thkz

ceez

Link to comment
Share on other sites

Set /S Variable=value

This will set a system variable.

jrzycrim, I tried that but it didnt add it to the list in system properties. It did add it to the variables using the set command....now it's listed as /s PLB_TERM=ANSI I typed it like this on c:\

SET /S PLB_TERM=ANSI

any extra ideas on that one? :)

thkz for your help

PS- how do i delete that variable now :) the set /? command doesnt show how to remove :P

Link to comment
Share on other sites

I also need to add "G:\COMMANDS" to the Path variable that is already in the system.  How would I add that one?

"PATH"="G:\COMMANDS"???  wouldnt that erase all the info that is currently in the Path variable and insert the g:\command one??  oh so confused!!!!  :blink:

thkz

ceez

Not sure why some of your variables aren't being set.

About path, you can use this command to append to the current path:

path %path%;new path;another new path; etc...

path %path%;G:\COMMANDS

Link to comment
Share on other sites

jrzycrim, I tried that but it didnt add it to the list in system properties.  It did add it to the variables using the set command....now it's listed as /s PLB_TERM=ANSI I typed it like this on c:\

SET /S PLB_TERM=ANSI

any extra ideas on that one? :)

thkz for your help

PS- how do i delete that variable now :)  the set /? command doesnt show how to remove  :P

Sorry about that. I forget sometimes I'm using 4NT which is a different command processor than the standard one. It has a lot of extra features.

To remove that variable, try this:

set /s PLB_TERM=

Link to comment
Share on other sites

LOL jrzycrim...i havent finished typing my response and you've already beaten me to it! :) thkz!!!

I'll see if i can find a reason why those other variables are not being added.

just add the path command in that .reg file that I created?

Should the reg file then look like this? :

-=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=-

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]

"BRD_ROOT"="G:"

"BRD_SILDIR"="G:\SIL"

"PLB_PATH"="G:\;G:\PROGRAMS;G:\DATA;G:\COMMANDS"

"PLB_SYSTEM"="G:\COMMANDS"

"PLB_TERM"="ANSI"

"PLBWIN_ICON"="G:\BRD.ICO"

PATH %PATH%;G:\COMMANDS

-=-=-=-=-=--=-=-=-=-=--=-=-=-=-=--=-=-=-=-=-

thkz man!

Link to comment
Share on other sites

You can't add commands like that to a regfile. You would have to execute that path command from a batch file.

I've got an idea I'm going to test. BRB...

In the registry, the path value is an Expandable string value so that variables such as %systemdrive% will resolve correctly. What you should do is use regedit to edit the path variable directly: add ;G:\Commands to the end of the current value and export they Enviroment key, then open the new regfile and copy the path value from that. It will be in hex format; something like this:

"Path"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
 00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,3b,00,25,00,\
 53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,3b,00,25,\
 00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,5c,00,\
 73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,42,00,45,00,4d,\
 00,3b,00,43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,00,\
 46,00,69,00,6c,00,65,00,73,00,5c,00,45,00,78,00,65,00,63,00,75,00,74,00,69,\
 00,76,00,65,00,20,00,53,00,6f,00,66,00,74,00,77,00,61,00,72,00,65,00,5c,00,\
 44,00,69,00,73,00,6b,00,65,00,65,00,70,00,65,00,72,00,5c,00,00,00

Don't use this value, export the one from your own registry after you add your own paths.

Link to comment
Share on other sites

well i created a batch and added that line, ran it and then get this on the cmd box

C:\Documents and Settings\Tessa\Desktop>PATH C:\WINDOWS\system32;C:\WINDOWS;C:\W

INDOWS\System32\Wbem;"C:\Program Files\Norton SystemWorks\Norton Ghost\";C:\Prog

ram Files\Symantec\pcAnywhere\;G:\COMMANDS

looks great....but not on the system properties......**** THIS SYSTEM PROPERTIES WINDOW!!!! If I cant get those in there I will have to try this on a system and if it all works without the visualization issue then I will have to educate everyone of this new automated change that doesnt add the variables in the system properties...

jrzycrim, you've given me excellent options....any last thoughts!?!?!?! :unsure:

Man I love forums!!! :w00t:

I've got an idea I'm going to test. BRB...
i didnt read this line, thanks!!! :)
Link to comment
Share on other sites

You can't add commands like that to a regfile. You would have to execute that path command from a batch file.

I've got an idea I'm going to test. BRB...

In the registry, the path value is an Expandable string value so that variables such as %systemdrive% will resolve correctly. What you should do is use regedit to edit the path variable directly: add ;G:\Commands to the end of the current value and export they Enviroment key, then open the new regfile and copy the path value from that. It will be in hex format; something like this:

"Path"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
 00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,3b,00,25,00,\
 53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,3b,00,25,\
 00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,5c,00,\
 73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,42,00,45,00,4d,\
 00,3b,00,43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,00,\
 46,00,69,00,6c,00,65,00,73,00,5c,00,45,00,78,00,65,00,63,00,75,00,74,00,69,\
 00,76,00,65,00,20,00,53,00,6f,00,66,00,74,00,77,00,61,00,72,00,65,00,5c,00,\
 44,00,69,00,73,00,6b,00,65,00,65,00,70,00,65,00,72,00,5c,00,00,00

Don't use this value, export the one from your own registry after you add your own paths.

well i for sure wasnt going to think of that one!

I will do that and since we always use the same apps in every system we setup it should be an issue since it's writing the same paths....right?

jrzycrim thkz again for your time....it's 2:00am time to hit the pillow....i'll check in tomorrow

THKZ!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...