Environment Variables...

G

Guest

Start
Control Panel
System
Advanced
Environment Variables

Under the "System variables" section...

Is there any way to set a system variable from the command-line? When
installing a corporate application, I want to set a variable from a batch
file. Then, later on, read that variable from a batch file and make
appropriate changes based on that variable. When using the "set" command from
a command-line, the variable only remains set while that specific command
window is open. I need to be able to set the variable to a specific value,
have it remain constant, and be able to change it using a batch file under a
command window.

Thanx.
 
G

GTS

There used to be a Microsoft utility called Winset that could do this in
Windows 9X. To my knowledge, there is no equivalent for NT versions of
Windows. The Evar can be added to the registry by a .reg file but will not
be globally visible until the next reboot or logon. Better would be a vbs
script to add the Evar to the registry and broadcast a message to update the
global availability. See the article below-

How to propagate environment variables to the system
http://support.microsoft.com/?kbid=104011
 
G

Guest

Gotchya.

So, from a command prompt, within a batch file, how could I accomplish this?

Say I want to create a system variable called "ServerPointer" and set it to
a value of "10.20.30.40". Then, the goal is to be able to run a batch file at
any time that could look at the value of said variable and "swap" it based on
its current value. If it is set to "40", change it to "50" and vice-versa.

Thanx again.
 
B

billious

Steven Sinclair said:
Start
Control Panel
System
Advanced
Environment Variables

Under the "System variables" section...

Is there any way to set a system variable from the command-line? When
installing a corporate application, I want to set a variable from a batch
file. Then, later on, read that variable from a batch file and make
appropriate changes based on that variable. When using the "set" command
from
a command-line, the variable only remains set while that specific command
window is open. I need to be able to set the variable to a specific value,
have it remain constant, and be able to change it using a batch file under
a
command window.

Thanx.

Possibly the simplest method is to write the variable to a file & read it
back in the second process

You could try

first batch:

echo %varname%>filename.txt

second batch: (all on one line)

if exist filename.txt for /f "delims=" %%i in (filename.txt) do set
varname=%%i

(where the "delims=" is not required if the variable contains anly
alphanumerics)

Another method with the same theme is this

first batch:

set var1>filename.txt

second batch: (all on one line)

if exist filename.txt for /f "delims=" %%i in (filename.txt) do set %%i

Since "var1" will be placed in filename.txt by the first, in the format
"var1=whatever" then the second neatly restores the variables into their
original names.

By extension, and caution : you could use this second method to set multiple
variables.
set var1>filename.txt
will output the current content of any variable whose name starts "var1"
(like VAR1 and also VAR12) which can be a blessing or a curse.

....and >filename will create a NEW file 'filename', but >>filename will
APPEND to the contents of filename (or create a new file)

Hence
set var1>filename.txt
set user>>filename.txt

will create (& load with the one for/f... command) all of the variables
starting var1 and also those starting USER (like USERDOMAIN,USERNAME,
USERPROFILE)

XP, or more generally NT+ batch techniques are discussed in
alt.msdos.batch.nt

HTH

....Bill
 
W

Wesley Vogel

Open a command prompt, type set /? and hit enter.

Start | Run | Paste this in the box and click OK...

hh ntcmds.chm::/set.htm

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 
T

Torgeir Bakken \(MVP\)

Steven said:
Start
Control Panel
System
Advanced
Environment Variables

Under the "System variables" section...

Is there any way to set a system variable from the command-line?

Yes, use Setx.exe with the -m switch.

For WinXP, Setx.exe is included as a utility in the support tools
installation package (on your WinXP CD) installed by suptools.msi.

It is also in the free part of Win2000 Resource Kit:
http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/setx-o.asp

I would think you can use either version on either OS version.


Also note that there is updated versions of Support Tools available:

Windows XP Service Pack 2 Support Tools
http://www.microsoft.com/downloads/details.aspx?FamilyID=49ae8576-9bb9-4126-9761-ba8011fabf38

If you don't have a WinXP CD, or you want to use the latest version of
the tools, it should be ok to install and use the downloadable SP2
version of Support Tools on a WinXP SP1 computer.
 
T

Torgeir Bakken \(MVP\)

GTS said:
There used to be a Microsoft utility called Winset that could do
this in Windows 9X. To my knowledge, there is no equivalent for
NT versions of Windows. (snip)
Hi,

Setx.exe can do this. See my other post in this thread.
 
G

Guest

Thanx for all the help guyz, but I figured out a better (invisible to the
user) way to do what I need done.

I simply use the reg add command from a command prompt within a batch file
with echo off.

Works like a charm.

Thanx again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top