Jump to content

setting and activation of environment variables via batch script


Recommended Posts

Hello,

I would like to use relative links for Windowsexplorer. The only way I found was to set and environment variable and then use this variable for the link.

I tried to set the environment variable with the batch command "reg add". This creates/changes the registry entry. But the variable is not yet active.

With the script below the following happens:

Step 1:

"c" will create the variable _test. This can be checked by pressing "r".

If I open a new cmd and enter

"set _test", the variable "_test" results as not defined.

Step 2:

If I open start - settings - control panel - system - advanced - Environment Variables, _test is defined.

If I click "Ok" (or "Edit" - "Ok" - "Ok") and then open a new cmd and enter

"set _test", the variable "_test" is correctly defined.

Now my question:

Does anyone know, how to perform Step 2 automatically without a new login?

BR

greg

Here is the test script:

@ECHO OFF
echo:
echo:
ECHO This will set an environment variable "_test"
:BEGINN
echo:
Echo use current drive path © use Server path (s)
Echo open regedit and show variable ®
Echo Abort (a)
set /P eingabe=
if %eingabe% == c goto current
if %eingabe% == s goto server
if %eingabe% == r goto open_regedit
if %eingabe% == a goto ENDE
goto BEGINN

:current

set temp_current_folder=%CD%
reg add HKEY_CURRENT_USER\Environment /v _test /d "%temp_current_folder%" /f
rem is there a difference? reg add HKCU\Environment /v _test /d "%temp_current_folder%" /f
ECHO:
ECHO _test has been set to
ECHO:
reg query HKEY_CURRENT_USER\Environment /v _test

GOTO BEGINN

:server

reg add HKEY_CURRENT_USER\Environment /v _test /d "\\test_server\test_path" /f
ECHO:
ECHO _test has been set to
ECHO:
reg query HKEY_CURRENT_USER\Environment /v _test

GOTO BEGINN

:open_regedit
set LastKey="HKEY_CURRENT_USER\Environment"

set Key=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit
reg add %Key% /f /v "LastKey" /d %LastKey%
start regedit.exe


GOTO BEGINN


:ENDE

Link to comment
Share on other sites

Maybe reading the Help file for the set command will give you some ideas (see attachment).

Thanks

I had a look on this but I didn't find anything. The set command is always temporary.

Then I decided to try out the Windows XP SP2 Support Tools. (It's not the best solution, because an aditional program is required...)

The solution is:

Use the setx.exe from

http://www.microsoft.com/downloads/details...;displaylang=en

I tried this on WinXPx32 and WinXPx64 just by using the setx.exe without installing the support tools. This works fine:

Setting variable _test = "test1"

\\server_with_setx\path_to_setx\setx.ex _test "test1"

or, if setx.exe has been copied to C:\WINNT (on a x32 machine):

setx _test "test1"

Deleting _test:

\\server_with_setx\path_to_setx\setx.exe _test ""

or

setx _test ""

(

It's quite interesting:

reg add HKEY_CURRENT_USER\Environment /v _test /d "test1" /f

setx _test2 "test2"

results in both variable beeing available to a new cmd

)

So far

Greg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy