Jump to content
Sign in to follow this  
dancer58

dos command in autoit

Recommended Posts

dancer58

I'm sure this is very simple

I am trying to do a dos command but it doesn't change

Is %programfiles% in dos the same as @ProgramFilesDir in autoit ?

$rc = _RunDos('set programfiles=e:\backups')

MsgBox(0, "program files (should be e:\backups):", @ProgramFilesDir)

"set programfiles=e:\backups" works in dos "changedirectorys.cmd"

Thanks

Share this post


Link to post
Share on other sites
PsaltyDS

I'm sure this is very simple

I am trying to do a dos command but it doesn't change

Is %programfiles% in dos the same as @ProgramFilesDir in autoit ?

Yes. But not the same as @ProgramsDir and @ProgramsCommonDir, which are annoyingly similar. I really wish those had been named @ProfileProgramsDir, or something to be more clear, but it's too late to change it now without breaking legacy code.

$rc = _RunDos('set programfiles=e:\backups')

MsgBox(0, "program files (should be e:\backups):", @ProgramFilesDir)

"set programfiles=e:\backups" works in dos "changedirectorys.cmd"

Thanks

From inside AutoIt, you could just use EnvSet(). If you want to set System Environment variables, then you are better off writing to the registry at:

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
dancer58

I tried EnvSet but it didnot change "@ProgramFilesDir"

Am I missing something

;$rc = _RunDos('set programfiles=e:\backups')

EnvSet("Programfiles", "e:\backups")

MsgBox(0, "program files (should be e:\backups):", @ProgramFilesDir)

Share this post


Link to post
Share on other sites
dancer58

Thanks

It works fine but the way I will use it I do not want to write directly to the registry

I am using it on PEBuilder. The CD will be used on different machines with diferent operating systems

Share this post


Link to post
Share on other sites
PsaltyDS

I tried EnvSet but it didnot change "@ProgramFilesDir"

Am I missing something

;$rc = _RunDos('set programfiles=e:\backups')

EnvSet("Programfiles", "e:\backups")

MsgBox(0, "program files (should be e:\backups):", @ProgramFilesDir)

You have gotten into the maze of twisty little passages that is "Shell Environments" and how they inherit environment variables. When you run EnvSet() you have only changed the value for any NEW shells that you spawn from that script. Reading the @ProgramFilesDir macro does not go out to the shell, but GetEnv() does. Try this:

ConsoleWrite("Debug: @ProgramFilesDir = " & @ProgramFilesDir & @LF)
ConsoleWrite("Debug: %ProgramFiles% = " & EnvGet("ProgramFiles") & @LF)
EnvSet("ProgramFiles", "G:\Bogus Value\")
ConsoleWrite("Debug: @ProgramFilesDir = " & @ProgramFilesDir & @LF)
ConsoleWrite("Debug: %ProgramFiles% = " & EnvGet("ProgramFiles") & @LF)

Run(@ComSpec & " /k SET")

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
dancer58

I think I am over my head :)

envset appears to work but @ProgramFilesDir must look elsewhere

Does anyone know what @ProgramFilesDir looks at or is there another autoit command I can use

I need to change several environment setting, run a program, then set them back where they were

I can do it with batch file but need to be able get environment from the computor i'm on

Edited by dancer58

Share this post


Link to post
Share on other sites
PsaltyDS

I think I am over my head ;)

envset appears to work but @ProgramFilesDir must look elsewhere

Does anyone know what @ProgramFilesDir looks at or is there another autoit command I can use

I need to change several environment setting, run a program, then set them back where they were

I can do it with batch file but need to be able get environment from the computor i'm on

The @ProgramFilesDir macro reflects what %ProgramFiles% was when AutoIt started. If you do EnvUpdate() it will get a new value, but not what you set with EnvSet(). It will get entirely new environment variable values as though AutoIt had exited and be restarted in a new shell. This new value will reflect what is stored in the System Environment Variable keys, not what you changed with EnvSet().

Like I said, twisty maze of passages... :)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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.