vikashbitm2010 Posted November 7, 2016 Share Posted November 7, 2016 I have following in batch file: echo myfile = D:\\myfile.txt >> %qm_AttachmentsFile% In above, env variable is " qm_AttachmentsFile " where File path is getting appended. How i can do through AutoIt ? Any suggestion ? Link to comment Share on other sites More sharing options...
Anoop Posted November 7, 2016 Share Posted November 7, 2016 Use envset for temporarily setting the environment variable. Link to comment Share on other sites More sharing options...
vikashbitm2010 Posted November 7, 2016 Author Share Posted November 7, 2016 Thanks for the reply !! I am using like this: EnvSet("qm_AttachmentsFile" ," D:\myfile.txt") But its not working.. Link to comment Share on other sites More sharing options...
Anoop Posted November 7, 2016 Share Posted November 7, 2016 (edited) Are you getting any error? Please note, Once AutoIt closes, the variables will cease to exist. If you want to permanently set, use registry write operation. Search this forum. Edited November 7, 2016 by Anoop Link to comment Share on other sites More sharing options...
BrewManNH Posted November 7, 2016 Share Posted November 7, 2016 Ignore the posts above, they're not helping you. You want to use EnvGet to retrieve an environment variable's value. So to get the value that qm_AttachmentsFile contains you'd use EnvGet("qm_AttachmentsFile") and that will return the value. JLogan3o13 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Anoop Posted November 7, 2016 Share Posted November 7, 2016 (edited) 2 hours ago, BrewManNH said: Ignore the posts above, they're not helping you. @vikashbitm2010, So let BreManNH post help you. If you need any more details, please feel free to ask me. Edited November 7, 2016 by Anoop Link to comment Share on other sites More sharing options...
BrewManNH Posted November 7, 2016 Share Posted November 7, 2016 Anoop, I'm sorry if you got all hurt because I told the truth. The OP was asking how to use an environment variable in a script. Everything you posted was telling him how to set the variable which is not what he needed. If the OP kept following your advice he'd have gotten more confused and wondering why it wasn't working. You weren't helping, you were just confusing the issue. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Anoop Posted November 8, 2016 Share Posted November 8, 2016 5 hours ago, BrewManNH said: Anoop, I'm sorry if you got all hurt because I told the truth. The OP was asking how to use an environment variable in a script. Everything you posted was telling him how to set the variable which is not what he needed. If the OP kept following your advice he'd have gotten more confused and wondering why it wasn't working. You weren't helping, you were just confusing the issue. Unfortunately, I don't think that there is some truth . His question clearly states that, he has a batch file with an environment variable which is getting appended with some file path. And he wants to do it with Autoit. Per my knowledge, envget will not do this. vikashbitm2010 1 Link to comment Share on other sites More sharing options...
vikashbitm2010 Posted November 8, 2016 Author Share Posted November 8, 2016 Hi Anoop, Thanks for understanding my query. Here you described in the same way. EnvGet will not work in this case. I have req with autoit as follows: There is an environment variable " qm_AttachmentsFile " which is added to the process environment already during my application execution. Now The value of the environment variable "qm_AttachmentsFile" should be the the full pathname to the file. And It is very successful with the batch file: echo myfile = D:\\myfile.txt >> %qm_AttachmentsFile% In above line present in batch file, the value as full pathname to the file is getting appended in the environment variable " qm_AttachmentsFile ". But I dont want to use batch file, so I want to do this through AutoIt script. Any idea will be appreciated. Link to comment Share on other sites More sharing options...
Anoop Posted November 8, 2016 Share Posted November 8, 2016 (edited) EnvSet("qm_AttachmentsFile" ," D:\myfile.txt") MsgBox(0,"",EnvGet("qm_AttachmentsFile")) The above script is correctly setting the environment variable and I can get it back using EnvGet. But please note - A environment variable set in this way will only be accessible to programs that AutoIt spawns (Run(), RunWait()). Once AutoIt closes, the variables will cease to exist. For permanently setting, you can use the script provided in the below post as reference. Edited November 8, 2016 by Anoop Link to comment Share on other sites More sharing options...
vikashbitm2010 Posted November 8, 2016 Author Share Posted November 8, 2016 Hey guys, I tried with the following and its working for me now: Run(@ComSpec & " /k echo log = D:\\myfile.txt >> %qm_AttachmentsFile%", "", @SW_HIDE) Thanks. Link to comment Share on other sites More sharing options...
Anoop Posted November 8, 2016 Share Posted November 8, 2016 Hi vikashbitm2010, Great to know that you solved your issue. 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