Autoit automated programming (1)

Source: Internet
Author: User
Autoit 2 ~ Run Program Or open a file.

1, Run the program
Run Commands or functions are used to run external executable files.

Au3:
Run ("File Name"[,"Working directory"[, Flag])

Example:

Au3:
Run ("notepad.exe ")

In the above example, no program" Notepad.exe ", Why can it still be executed? This is because they will automatically search for the target file in the directory where the script is located. If yes, they will run. Otherwise, they will go to the system folder ( % PATH % .
Note:
A ) Some programs must be given a "working directory" to run successfully!
B ) Providing a complete file path helps slightly improve program reliability.
C ) Ahk Of Run Commands can be used to run programs and open files directly, while Au3OfRunFunctions can only be used to run programs (executable files) or PASS Parameters to open a program to the target file.
Of course, the function of running a program is not just that simple. We can also specify the initial state of the running program, for example, to maximize the display of the running notepad window (or minimize or hide ):
[Example] 2.1.2 ]
Au3:
Run ("notepad.exe", "", @ sw_maximize) 

2Open a file
As mentioned above, Ahk Of Run Command to open the file directly, and Au3 Of Run Functions can only be used to run programs, so the method of opening files is a bit different: Ahk The script can directly provide the target file, while Ahk The associated program of the file will be automatically run to open it; and Au3 You must pass parameters to open the target file for a program.
[Example] 2.2.1 ]
Ahk :
Run, myfile.txt
Run, notepad.exe myfile.txt
Au3:
Run ("notepad.exe myfile.txt ")

PS: Au3Provided in the form of a "function:
Function (param1, param2 ,...)

3Run the program as a command line
You can consider running the command line interpreter of the system ( Cmd.exe/command.com ), And then specify the command to be executed and pass the parameter.
Suppose we want to execute the command" Dir C: \ WINDOWS \ SYSTEM 32" To list all files and subdirectories in a specified directory.
[Example] 2.3.1 ]
Ahk :
Run, % comspec %/K dir c: \ windows \ system32
Au3:
Run (@ comspec & "/K dir c: \ windows \ system32 ")
Note:
A ) Comspec Is a variable or macro built in the script to indicate the location of the command line interpreter.
B ) /K The parameter indicates "executing the specified string command but retaining it". If it is changed /C It indicates "executing the specified string command and then final disconnection ". The intuitive explanation is: /K The Command Prompt window will be retained after the command is executed, while /C The Command Prompt window will be closed after the command is executed.
C) Symbol"&"YesAu3String connector.

Attach my two paragraphsCode:

; Run ("rundll32.exe shell32.dll, control_rundll NCPA. CPL, 2 ")
; Run ("notepad.exe D: \ NW. PS1 ")
$ File = fileopen ("D: \ NW. PS1", 0); only files can be opened for operation, but files cannot be seen

; Check whether the opened file is readable
If $ file =-1 then
Msgbox (0, "error", "file cannot be opened .")
Exit
Endif

; Read a line of text each time until the end of the file.
While 1
$ Line = filereadline ($ file)
If @ error =-1 then exitloop
Msgbox (0, "Read row:", $ line)
Wend

 

========================================================== ==================

Dim $ title
Dim $ OK _control
$ Title = "about calculator"
$ OK _control = "[Class: button; text: OK]"
Winactivate ($ title)
Controlclick ($ title, "", $ OK _control)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.