Jump to content

Help needed


Skitty
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • Developers

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

  • Developers

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

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

  • Developers

Some one PLEASE HELP!

.. and stop being an impatient child.... Edited 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

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
Link to comment
Share on other sites

  • Developers

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

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
Link to comment
Share on other sites

  • Developers

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

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
Link to comment
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!

Link to comment
Share on other sites

  • Developers

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...