Sign in to follow this  
Followers 0
Autoxics

Read And Execute Script From A Text File?

29 posts in this topic

Hello folks!

I was wondering if it is possible for autoit to read and execute a command from a simple txt file,

let me explain, lets say i have a txt file that has this text/script in it Run("Notepad.exe", "", @SW_MAXIMIZE)

and the compiled au3 script would when executed read and execute this text as it would,if it was writend in the au3 script to begin with,

Any help is appreciated!

Share this post


Link to post
Share on other sites



I was going to say to look at "Execute" in the helpfile, but it seems to be pretty limited in what it can actually do.


AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

This worked when I tried it using a .txt file and Run('Notepad.exe'):

$File = FileOpenDialog('Open File', @ScriptDir, 'Text (*.txt)')
Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & FileGetShortName($File))

Edit:

I also saved the text file with this:

MsgBox(0, 'Info', 'It worked')
only in it, and ran the above code, and got the message box too.

Thanks for the question, I would have not thought to do this ever if you hadn't asked :)

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

This worked when I tried it using a .txt file and Run('Notepad.exe'):

$File = FileOpenDialog('Open File', @ScriptDir, 'Text (*.txt)')
Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & FileGetShortName($File))

Edit:

I also saved the text file with this:

MsgBox(0, 'Info', 'It worked')
only in it, and ran the above code, and got the message box too.

Thanks for the question, I would have not thought to do this ever if you hadn't asked :)

Thank you Aswell, it worked,! Hurray! :(

Great!

Share this post


Link to post
Share on other sites

Thank you Aswell, it worked,! Hurray! :)

Great!

Actualy i ve got a Smal problem if anyone has time

I am trying to do this without the dialogbox in thi sway is this correct?

$File = FileOpen(@ScriptDir ,"test.txt")
Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & FileGetShortName($File))

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Actualy i ve got a Smal problem if anyone has time

I am trying to do this without the dialogbox in thi sway is this correct?

$File = FileOpen(@ScriptDir ,"test.txt")
Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & FileGetShortName($File))
No just use the File Path, don't use Open at all.

Edit:

Like:

$File = @ScriptDir & '\test.txt'
Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & FileGetShortName($File))
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thank you very much SmOke_N!

it worked perfect,

Share this post


Link to post
Share on other sites

This worked when I tried it using a .txt file and Run('Notepad.exe'):

$File = FileOpenDialog('Open File', @ScriptDir, 'Text (*.txt)')
Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & FileGetShortName($File))

I did something similar to this idea a while ago.

I wrote scripts to an ini file then had a main script run the commands, it copied the section out of the ini file and created a temp.au3 file and ran it.

It had a run=1 section

When it was run=1 it ran the first section and every time I would increment the run number to move on to the next section after a reboot.

What this did was allowed us to change things for the installer without writting the script and recompiling it each time

Ini file contents..

[Count]
Run=1

[Run1]
1=#include "c:\Drivers\Fujifilm\includes\GuiConstants.au3"
2=GuiCreate('Updating SID', 456, 208,(@DesktopWidth-456)/2, (@DesktopHeight-208)/2)
3=$Label_sid = GuiCtrlCreateLabel("Please wait" & @crlf & "Changing computer name" & @crlf & "and SID", 30, 30, 380, 130)
4=GuiCtrlSetFont ($Label_sid, 24)
5=GuiSetState()
6=Sleep (1000)
7=RunWait ("C:\Drivers\Fujifilm\Newsid.exe /a", "C:\Drivers\Fujifilm")


[Run2]
1=#include "c:\Drivers\Fujifilm\includes\GuiConstants.au3"
2=GuiCreate('Converting Drive C', 456, 160,(@DesktopWidth-456)/2, (@DesktopHeight-160)/2)
3=$Label = GuiCtrlCreateLabel("The computer will reboot and" & @crlf & "Convert the C drive to NTFS", 30, 30, 380, 130)
4=GuiCtrlSetFont ($Label, 20)
5=GuiSetState()
6=Sleep (5000)
7=Run ("Convert c: /FS:NTFS")

[Run3]
1=#include "c:\Drivers\Fujifilm\includes\GuiConstants.au3"
2=GuiCreate('Converting Drive D', 456, 160,(@DesktopWidth-456)/2, (@DesktopHeight-160)/2)
3=$Label = GuiCtrlCreateLabel("The computer will reboot and" & @crlf & "Convert the D drive to NTFS", 30, 30, 380, 130)
4=GuiCtrlSetFont ($Label, 20)
5=GuiSetState()
6=Sleep (5000)
7=Run ("Convert D: /FS:NTFS")


[Run4]
1=MsgBox (262144,"Customise","Insert customisation CD and Click OK")
2=For $i = 65 to 89
3=  $Type = DriveGetType (Chr ($i) & ":")
4=  if $Type = "CDROM" then 
5=      $CDROM = Chr ($i) & ":\"
6=      exitloop 
7=      Endif
8=  Next
9=WaitForDrive ($CDRom)
10=$Ready = FileExists ($cdrom & "Customise.exe")
11=While $Ready = 0
12=$Answer = MsgBox (262145,"Error","Can not find Customisation" & @crlf & "Insert customisation CD and Click OK")
13=If $Answer = 2 then exitloop
14=WaitForDrive($CDRom)
15=Sleep (500)
16=$Ready = FileExists ($cdrom & "Customise.exe")
17=Wend 
18=If $Ready = 1 then 
19= Run ($CDRom & "Customise.exe", $Cdrom)
;;20=Change Sals entries
;;21=ShutDown (6)
20=Else
21= iniwrite ("c:\Drivers\Fujifilm\dpc6install.ini","Count","Run","4")
22= Endif
23=Func WaitForDrive($Drive)
24= For $b = 1 to 10
25= If DriveStatus ($Drive) = "Ready" then 
26=     Return "Ready"
27= Else
28= Sleep (500)
29= Endif
30= Next
31=Return "NotReady"
32=EndFunc

And teh actual program that did the running of the ini file sections

$iniFile = StringTrimRight ( @scriptname, 3 )& "ini" 
$Count = iniread( $iniFile,"Count","Run","1")
$Section = IniReadSection ($iniFile,"Run" & $count)
if fileexists(@tempdir &"\temp.au3") then FileDelete (@tempdir &"\temp.au3")
For $i = 1 to Ubound ($Section)-1
FileWriteLine (@tempdir & "\temp.au3",$Section[$i][1])
Next

If Ubound ($Section)-1 <> -1 then
$Count +=1
If not StringinStr (FileGetAttrib($iniFile),"+R")then iniwrite ($iniFile,"Count","Run",$Count)
RunWait(@AutoItExe & ' /AutoIt3ExecuteScript ' & @tempdir & '\temp.au3')
Endif

Share this post


Link to post
Share on other sites

Hello again since this worked, wouldent it be possible to retrieve the script from the clipboard?

just realised it could be pretty usefull aswell,if infact it could read the script from the clipboard

Share this post


Link to post
Share on other sites

#10 ·  Posted

Hello again since this worked, wouldent it be possible to retrieve the script from the clipboard?

just realised it could be pretty usefull aswell,if infact it could read the script from the clipboard

yes

$File = Clipget()
Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & FileGetShortName($File))

but you had better be sure of the code... so maybe

$File = Clipget()
if fileexists($file) then Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & FileGetShortName($File))

NEWHeader1.png

Share this post


Link to post
Share on other sites

#11 ·  Posted

I tried that but with no succes, iam using latest beta,

I added this to the clipboard

Run("Notepad.exe", "", @SW_MAXIMIZE)

Share this post


Link to post
Share on other sites

#12 ·  Posted

sorry, for command lines like

Run("Notepad.exe", "", @SW_MAXIMIZE)

remove the "if Fileexists() then" part

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#13 ·  Posted

Like this

$File = Clipget()

Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & FileGetShortName($File))

Share this post


Link to post
Share on other sites

#14 ·  Posted

this works

$TLoc = @TempDir & "\test.au3"
$TInfo = ClipGet()
FileWrite($TLoc, $TInfo)

If FileExists($TLoc) Then
    $File = FileGetShortName($TLoc)
    RunWait(@AutoItExe & " " & $File)
    FileDelete($TLoc)
Else
    MsgBox(64, "Error", "The file was not found  ", 2)
EndIf

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#15 ·  Posted

My good that looked my system up totaly!

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

My good that looked my system up totaly!

remember that you have to copy a script to the clipboard before you can run it

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

#17 ·  Posted

1

I just tested it again and it worked fine

2

if you look at the code in "IE.au3 Builder" in my sig below....

it has the same script.. ( almost )

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#18 ·  Posted

I try it out, thnaks again , hade to restart the system , but everythings fine here, i am allso trying another workaround,, thanks again!

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Here is the final script, that makes autoit read and execute a script that is currently stored in window clipboard

thanks for the help with this guys!

I call this script Clip2Exec :)

$file = FileOpen("Clip2Exec.txt", 1)
Sleep(50)
$bak = ClipGet()
FileWrite($file, "" & $bak)
FileClose($file)
Sleep(50)
$File = @ScriptDir & '\Clip2Exec.txt'
Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & FileGetShortName($File))
Sleep(100)
FileDelete("Clip2Exec.txt")

works with most au3 scripts,

Edited by Autoxics

Share this post


Link to post
Share on other sites

#20 ·  Posted

Here is the final script, that makes autoit read and execute a script that is currently stored in window clipboard

thanks for the help with this guys!

I call this script Clip2Exec :(

$file = FileOpen("Clip2Exec.txt", 1)
Sleep(50)
$bak = ClipGet()
FileWrite($file, "" & $bak)
FileClose($file)
Sleep(50)
$File = @ScriptDir & '\Clip2Exec.txt'
Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & FileGetShortName($File))
Sleep(100)
FileDelete("Clip2Exec.txt")

works with most au3 scripts,

I can't even tell you how many times I was playing with this yesterday :)

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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