TechnoMonster

Persisent variable across called batch procedures

4 posts in this topic

I'm using batch procedures to change a  desired network adapter IP and gateway addresses by prompting the user for the Idx# of their wired LAN network adapter.

Later, in a separate batch procedure, I'd like to be able to return "that" adapter to DHCP.

 

This is what the fist batch proc looks like:

   @echo OFF

   :start

   cls

   echo.

   NetSh Interface IPv4 Show Interfaces

   echo. 

   set input=

   echo Enter the "Idx #" above of the Wired Ethernet Network Adapter in your system: 

   echo.

   set /p input=""

   if "%input%" == "" goto start

   netsh interface ipv4 set address name=%input%  source=static addr=126.19.0.13 mask=255.0.0.0 gwmetric=1

   exit

 

Later, in a second batch procedure, I'd like to simply do something like:

   netsh interface ipv4 set address name=%input%  source=dhcp

but the variable %input% is no longer known.

Suggestions?  Thanks.

Share this post


Link to post
Share on other sites



C:\tmp>type test1.bat
@echo off

set "timeOfTest1=%time%"

echo "Test 1 time: %timeOfTest1%"

C:\tmp>type test2.bat
@echo off

echo "Time of test 1 execution was: %timeOfTest1%"

C:\tmp>test1.bat
"Test 1 time:  0:34:13.80"

C:\tmp>test2.bat
"Time of test 1 execution was:  0:34:13.80"

But what does that have to do with AutoIt?


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

I"m calling these procedures from a single instance of an AutoIT program.  I need the variable that the user specifies in an earlier procedure call to be used in a later procedure call.

Share this post


Link to post
Share on other sites

You can use setx instead of set. You may have to run your script as admin though to be able to set Windows environment variables (add #RequireAdmin on top of your script). This works for me:

test1.bat:

@echo off
setx timeOfTest1 "%time%"
echo "Test 1 time: %timeOfTest1%"
pause

test2.bat:

@echo off
echo "Time of test 1 execution was: %timeOfTest1%"
pause

script:

#RequireAdmin
RunWait("c:\tmp\test2\test1.bat")
RunWait("c:\tmp\test2\test2.bat")

Good luck.


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
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