Sign in to follow this  
Followers 0
Skitty

Help needed

40 posts in this topic

#1 ·  Posted (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 by xJSLRx

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

;)

O.k... there, I removed it.

Edited by xJSLRx

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

Some one PLEASE HELP!


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by xJSLRx

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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.


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 by xJSLRx

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

Eh! Make a bug report.

No, wait... feature request. This is really something.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

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!)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#14 ·  Posted (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.

Jos

How 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)

EndIf

EDIT: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 by xJSLRx

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#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!


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

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")

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

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.


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

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!


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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  
Followers 0