Skitty Posted October 14, 2010 Share Posted October 14, 2010 (edited) I need help on how to add a function in AutoIT that will create a batch file in C:\temp and input some text, as in commands, and execute it. Is this possible? I need the script to check and see if the .bat file is there and if not, create it when I press the button! and then have it write some text in it just like the "iniwrite(" command. If Not FileExists("C:\temp") Then DirCreate("C:\temp") ;This line works. ;If Not FileExists("C:\temp\a.bat") Then Batcreat("C:\temp\a.bat") ;I need this line to creat the batch file. ;batwrite("MY ARGUMENTS, COMMANDS ETC HERE!") ;I need this line to add text inside the batch file. _Menu() Func _Menu() $MainGUI = GUICreate("Menu", 170, 50, -1, -1) $Launcher = GUICtrlCreateButton("launch .bat", 10, 10, 150) GUISetState() While 1 $nMsg = GUIGetMsg() Select Case $nMsg = -3 Exit Case $nMsg = $Launcher _Launcher() EndSelect WEnd EndFunc Func _Launcher() batwrite() ShellExecute("C:\temp\a.bat") ;and then launch the .bat with this. EndFunc So how can this be done?!?!? Edited October 14, 2010 by xJSLRx Link to comment Share on other sites More sharing options...
Developers Jos Posted October 14, 2010 Developers Share Posted October 14, 2010 if this --->[x] has an "x" it means I'm still here waiting for help. I will change it when I get off. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Skitty Posted October 14, 2010 Author Share Posted October 14, 2010 (edited) O.k... there, I removed it. Edited October 14, 2010 by xJSLRx Link to comment Share on other sites More sharing options...
Skitty Posted October 14, 2010 Author Share Posted October 14, 2010 Some one PLEASE HELP! Link to comment Share on other sites More sharing options...
Developers Jos Posted October 14, 2010 Developers Share Posted October 14, 2010 (edited) C'mon man... Im trying to make thing work!so ... what is that confusing line doing there then? stick to the issue at hand.Anyway, have you even try to look at the helpfile on how to create a file and write information to it? Edited October 14, 2010 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Developers Jos Posted October 14, 2010 Developers Share Posted October 14, 2010 (edited) Some one PLEASE HELP!.. and stop being an impatient child.... Edited October 14, 2010 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ZacUSNYR Posted October 14, 2010 Share Posted October 14, 2010 If FileExists($tempfolder & $batchfile) Then FileDelete($tempfolder & $batchfile) $file = FileOpen ($tempfolder & $batchfile, 2) FileWrite($file, $lineone) FileWrite($file, $linetwo) FileClose($file) Read the help on FileOpen/FileWrite/FileWriteLine/FileClose. Link to comment Share on other sites More sharing options...
Skitty Posted October 14, 2010 Author Share Posted October 14, 2010 (edited) so ... what is that confusing line doing there then? stick to the issue at hand.Anyway, have you even try to look at the helpfile on how to create a file and write information to it?Yes, actually I have. And it says nothing about creating batch files and writing in them, only .ini files.EDIT: I used the help function in the program. Edited October 14, 2010 by xJSLRx Link to comment Share on other sites More sharing options...
Developers Jos Posted October 14, 2010 Developers Share Posted October 14, 2010 Yes, actually I have. And it says nothing about creating batch files and writing in them, only .ini files.As the previous poster explained... look at those file???? functions since a batch file is just a simple file.The INI files are special thus have the standard Windows INI functions available.Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Skitty Posted October 14, 2010 Author Share Posted October 14, 2010 If FileExists($tempfolder & $batchfile) Then FileDelete($tempfolder & $batchfile) $file = FileOpen ($tempfolder & $batchfile, 2) FileWrite($file, $lineone) FileWrite($file, $linetwo) FileClose($file) Read the help on FileOpen/FileWrite/FileWriteLine/FileClose. I think you might be on to something! Thanks. Link to comment Share on other sites More sharing options...
Skitty Posted October 14, 2010 Author Share Posted October 14, 2010 (edited) If FileExists($tempfolder & $batchfile) Then FileDelete($tempfolder & $batchfile) $file = FileOpen ($tempfolder & $batchfile, 2) FileWrite($file, $lineone) FileWrite($file, $linetwo) FileClose($file) Read the help on FileOpen/FileWrite/FileWriteLine/FileClose. one problem, there is no filecreate() command is there? no matter how hard I try I cant find it. EDIT: I'm sorry but I think I found it at the last minute.... Edited October 14, 2010 by xJSLRx Link to comment Share on other sites More sharing options...
trancexx Posted October 14, 2010 Share Posted October 14, 2010 Eh! Make a bug report. No, wait... feature request. This is really something. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Developers Jos Posted October 14, 2010 Developers Share Posted October 14, 2010 one problem, there is no filecreate() command is there? no matter how hard I try I cant find it.EDIT: I'm sorry but I think I found it at the last minute....Remember this:.. and stop being an impatient child....In other words: Think, search, read and try something before posting... (this means you take more than 6 minutes for that!) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Skitty Posted October 14, 2010 Author Share Posted October 14, 2010 (edited) As the previous poster explained... look at those file???? functions since a batch file is just a simple file.The INI files are special thus have the standard Windows INI functions available.JosHow do I add a file path? I think I might be close to doing this.#include <A.bat>If Not _FileCreate("A.bat") Then $sFilePath = ("c:\temp.bat") MsgBox(4096,"Error", " Error Creating/Resetting bat. error:" & @error)EndIfEDIT:Ok so I almost have this figured out thanks to ZacUSNYR's helpful insight.this is what I've got#Include <File.au3>_FileCreate("c:\temp\file.bat") Edited October 14, 2010 by xJSLRx Link to comment Share on other sites More sharing options...
Skitty Posted October 14, 2010 Author Share Posted October 14, 2010 #Include <File.au3> If Not FileExists("C:\temp") Then DirCreate("C:\temp") If not FileExists("c:\temp\a.bat") Then _FileCreate("c:\temp\a.bat") _Menu() Func _Menu() $MainGUI = GUICreate("Menu", 170, 50, -1, -1) $Launcher = GUICtrlCreateButton("launch .bat", 10, 10, 150) GUISetState() While 1 $nMsg = GUIGetMsg() Select Case $nMsg = -3 Exit Case $nMsg = $Launcher _Launcher() EndSelect WEnd EndFunc Func _Launcher() ShellExecute("C:\temp\a.bat") ;and then launch the .bat with this. EndFunc YES! I've almost got this! Link to comment Share on other sites More sharing options...
Bert Posted October 14, 2010 Share Posted October 14, 2010 Question: Why are you trying to make a launcher to run batch files? You could do everything in AutoIt and make it much more tidy. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Skitty Posted October 14, 2010 Author Share Posted October 14, 2010 I can't seem to understand how this one part works. I can't get the filewrite("") command to work... If not FileExists("c:\temp\a.bat") Then _FileCreate("c:\temp\a.bat") FileWrite("A.bat ,hello") Link to comment Share on other sites More sharing options...
Bert Posted October 14, 2010 Share Posted October 14, 2010 (edited) You have to do fileopen first. Make sure you use the correct mode to set fileopen to write mode. Edited October 14, 2010 by MPH The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Skitty Posted October 14, 2010 Author Share Posted October 14, 2010 Question: Why are you trying to make a launcher to run batch files? You could do everything in AutoIt and make it much more tidy.Because It's pretty useful to have them both work in sync. Link to comment Share on other sites More sharing options...
Developers Jos Posted October 14, 2010 Developers Share Posted October 14, 2010 I can't seem to understand how this one part works. I can't get the filewrite("") command to work... If not FileExists("c:\temp\a.bat") Then _FileCreate("c:\temp\a.bat") FileWrite("A.bat ,hello") sigh, have you even seriously looked at the posted example by ZacUSNYR? Have you even tried to understand it? now... go away and do not come back till you have read it and do the researched and testing! SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. 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