Radish Posted September 19, 2016 Share Posted September 19, 2016 (edited) Hi, I have the following autoit script: #pragma compile(Icon, C:\Program Files (x86)\SYSTEM\AutoIt\Aut2Exe\Icons\AutoIt_Main_v10_48x48_256.ico) Run ("E:\BATCH\Launch Eraser Portable.bat") WinWaitActive ("Eraser") Send ("^e") WinWaitActive ("Preferences: Erasing") Send ("4") Send ("{ENTER}") WinWaitActive ("Eraser") Send ("!{SPACE}") Send ("n") Exit The line that starts "Run" points to the following batch file: set TMP=W:\TMP set TEMP=W:\TEMP start "" "E:\PORTABLES\SECURITY\Eraser 5.8.8.1 [PortApps]\EraserPortable.exe" The batch file code does the following: Resets the location of the system TMP folder to W:\TMP (but only for the program which is subsequently launched). Resets the location of the system TEMP folder to W:\TEMP (but only for the program which is subsequently launched). Then launches Eraser Portable. The value of this is that the system TMP and TEMP folders are only reset for the program Eraser Portable i.e. the system TMP and TEMP folders are not reset on a global scale. This is really crucial, that these folders only get reset for the program that is subsequently launched from within the script. (Hope I've expressed that clearly.) If it is possible I would like to do all of this from within the autoit script (thus eliminating the batch file). So is it possible to do this? And, how do I do it? Edited September 19, 2016 by Radish Operating System: Windows 7 Pro. x64 SP1 Link to comment Share on other sites More sharing options...
argumentum Posted September 19, 2016 Share Posted September 19, 2016 https://www.autoitscript.com/autoit3/docs/functions/EnvSet.htm https://www.autoitscript.com/autoit3/docs/functions/EnvUpdate.htm Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Anoop Posted September 19, 2016 Share Posted September 19, 2016 Hi, EnvSet will not set the environment variables permanently. The scope of the this environment variable will be to programs that the AutoIt program spawns. If the variable set is not getting effective, try calling EnvUpdate. To permanently set an environment variable we will have to use some other mechanism like registry manipulation or other utilities. Link to comment Share on other sites More sharing options...
Radish Posted September 21, 2016 Author Share Posted September 21, 2016 (edited) Thanks for the responses. However, I don't think that EnvSet along with EnvUpdate can do what I want to happen. By my reading EnvSet is a command to use that will create an environment variable - it doesn't seem to have any possibility of "resetting" an already existing Windows environment path to have a different target directory for programs spawned by the Autoit script. Also as the environment variable will vanish when the Autoit script exits it isn't of any use to me either. A full explanation the batch file that I gave as an example would be thus: set TMP=W:\TMP set TEMP=W:\TEMP start "" "E:\PORTABLES\SECURITY\Eraser 5.8.8.1 [PortApps]\EraserPortable.exe" The first line takes the Windows TMP directory (sometimes written as %TMP%) and sets any temporary output that the program the batch file launches to be written to the directory W:\TMP. In other words any temporary output by the program EraserPortable.exe that would normally be written to the %TMP% directory will be written to the directory W:\TMP. The second line takes the Windows TEMP directory (sometimes written as %TEMP%) and sets any temporary output that the program the batch file launches to be written to the directory W:\TEMP. In other words any temporary output by the program EraserPortable.exe that would normally be written to the %TEMP% directory will be written to the directory W:\TEMP. The third line is just to launch EraserPortable.exe. However, because of the two lines preceding the third line, any temporary files that the program would write to the system environment paths %TEMP% and %TMP% will be written to the directory locations given in the set command. This "resetting" of the locations of %TMP% and %TEMP% only apply to any programs that the batch file launches (i.e. spawns). That "redirecting" of output to does not occur for any program that is not launched by the batch file. Lastly, these "redirections" persist for any program launched by the batch file even after the batch exits. That is what I would like to do from within an Autoit script. Is it possible to do that? And, if so, how? P.S. I use this kind of batch file quite a lot on my system as it means that if I launch a program using that kind of batch file, and the program writes temporary files to %TMP% and/or %TEMP% then I can have the program sending its temporary files to a directory in a ramdisk. This saves a bit of cleaning up - shutdown the computer and the temporary files just disappear along with the ramdisk. Edited September 21, 2016 by Radish Operating System: Windows 7 Pro. x64 SP1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now