2. Run the program or open the file
1. Run the program
The Run t command or function is used to run an external executable file, and AHK can also use it to open the file directly.
AHK:
Run, target file [, working directory, Max|Min|Hide|UseErrorLevel, output PID variable]
AU3:
Run ( "File Name" [, "Working Directory" [, Flag]] )
[Example 2.1.1]
AHK:
Run,
AU3:
Run("")
None of the above examples give the path to the program "", so why can it still be executed? This is because they will automatically search for target files in the directory where the script is located, and run if there is, otherwise they will search in the system folder (%PATH%).
Notice:
A) Some programs must be given a "working directory" to run successfully!
B) Giving a complete file path helps slightly improve the reliability of the program.
C) AHK's Run command can be used to run programs and open files directly, while AU3's Run function can only be used to run programs (executable files) or pass parameters to allow a program to open the target file.
Of course, the function of running a program is not just that simple. We can also specify the initial state of running the program, such as letting the running Notepad window display (or minimize or hide):
[Example 2.1.2]
AHK:
Run, , , Max
AU3:
Run("", "", @SW_MAXIMIZE)
2. Open the file
As mentioned earlier, AHK's Run command can directly open a file, while AU3's Run function can only be used to run programs, so the way to open a file is a bit different: the target file can be directly given in the AHK script, and AHK will automatically run the associated program of the file to open it; while AU3 must pass parameters by the user themselves to allow a program to open the target file.
[Example 2.2.1 ]
AHK:
Run,
Run,
AU3:
Run(" ")
3. Run the program in the form of a command line
You can consider running the system's command line interpreter (/), then specifying the command to be executed and passing the parameters.
Suppose we want to execute the command "dir C:\WINDOWS\system 32" to list all files and subdirectories of the specified directory.
[Example 2.3.1]
AHK:
Run, %ComSpec% /k dir C:\WINDOWS\system32
AU3:
Run(@ComSpec & " /k dir C:\WINDOWS\system32")
Notice:
A) ComSpec is a variable or macro built into the script to indicate the location of the command line interpreter.
B) The /k parameter means "execute the command specified by the string but reserved", and if changed to /c, it means "execute the command specified by the string and then terminate". A more intuitive explanation for this is that /k will retain the command prompt window after executing the command, while /c will close the command prompt window after executing the command.
C) The symbol "&" is a string concatenator defined by AU3.
4. Special applications
A) Open the web page
[Example 2.4.1]
AHK:
Run,
Run, %A_ProgramFiles%\Internet Explorer\
AU3:
Run(@ProgramFilesDir & "\Internet Explorer\ ")
B) Open a special folder
Some special folders in the system have corresponding CLSIDs defined (please check the help document). We can use it to open the corresponding folder, such as opening the Recycle Bin:
[Example 2.4.2]
AHK:
Run ::{645ff040-5081-101b -9f 08-00aa 002f 954e}
AU3:
not applicable!
C) Run Control Panel Tools
Microsoft has provided us with a way to open a tool or project in the control panel through the command line, such as opening the system properties window:
[Example 2.4.3]
AHK:
Run control
AU3:
Run("control ")
For a detailed introduction to accessing the Control Panel project, please see this article: Article address.
D) Specify the search location and open the search window
Suppose we want to open a search window and specify the search location, such as C:\:
[Example 2.4.4 ]
AHK:
Run, find C:\
AU3:
not applicable!
E) Display the properties window of the specified file
Suppose we want to open the properties window of file "", then use the keyword properties and then connect to the target file:
[Example 2.4.5]
AHK:
Run, properties
AU3:
not applicable!
Note: AHK will automatically close the open property window before exiting!
F) Use "Explorer" to open the specified folder
We know that using Run, explorer C: or Run("explorer C:") can open the specified folder, but sometimes we need to open it in Explorer, and then we can use the keyword explore:
[Example 2.4.6]
AHK:
Run, explore C:
AU3:
run(" /e,C:\")
G) Print the specified file
To print the specified file, use the keyword print:
[Example 2.4.7]
AHK:
Run, print
AU3:
not applicable!
F) Use "Explorer" to open the specified folder
We know that using Run, explorer C: or Run("explorer C:") can open the specified folder, but sometimes we need to open it in Explorer, and then we can use the keyword explore:
[Example 2.4.6]
AHK:
Run, explore C:
AU3:
not applicable!
run(" /e,d:\")
This will do what you said to open the tree file
Previous page12345Next pageRead the full text