Jump to content
Sign in to follow this  
allen00se

Get a variable from command line to use in AutoIT script

Recommended Posts

allen00se

So I am knee deep in a script that I am writing and the last thing I need to get this to work is to be able to set a envvariable at the command line using comspec, and then have a function in AutoIT assign that EnvVariable to an AutoIT variable for later use. Here is the simplified version of what I want to happen.

Run(@comspec)

sleep(2000)

send('set pc_name=foo{enter}')

sleep(2000)

$pcname = EnvGet("pc_name")

MsgBox(4096, "Path variable is:", $pcname)

Right now the message box is just blank.

In theory this should work, after I use the 'set pc_name=foo' command, I can check the pc's EnvVariables and sure enough pc_name=foo. However, for some reason EnvGet is not able to grab that EnvVariable. However it does work with other preset EnvVariables such as 'computername' etc.

any ideas?

Edited by allen00se

Share this post


Link to post
Share on other sites
Realm

Hello allen00se,

Just a guess here, but wouldn't EnvSet('pc_name','foo') be more useful then send('set pc_name=foo{enter}').

Realm


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites
whim

Hi, allen00se

It looks like env vars in the cmd window are local (not visible ouside that session)

- open 2 cmd windows

- in cmd window #1 do a 'set pc_name=foo'; then do a 'set' -> your env var is there

- in cmd window #2 do a 'set' -> it's not available

HTH,

whim

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
Sign in to follow this  

×

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.