Difference between revisions of "Lua:shellExecute"

From Cheat Engine
Jump to navigation Jump to search
m (Added CodeBox Template.)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' shellExecute(''command'')
+
{{CodeBox|'''function''' shellExecute(''command'') ''':''' boolean}}
 
 
Executes a specific commandline command. The commands are the same you can type in the "run..." command and in the file header of an explorer window.
 
 
 
Example:
 
  shellExecute("<nowiki>http://cheatengine.org</nowiki>")
 
  shellExecute("calc")
 
  shellExecute("c:\")
 
  shellExecute("regedit")
 
  
 +
Executes the specified command using the operating system shell. The command can be a URL, executable name, folder path, registry editor, or any string you can use in the Windows "Run" dialog or Explorer address bar. On success the requested action (opening a URL, launching an application, opening a folder, etc.) is started.
  
 
===Function Parameters===
 
===Function Parameters===
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
 
!style="width: 80%;background-color:white;" align="left"|Description
 
!style="width: 80%;background-color:white;" align="left"|Description
 
|-
 
|-
|command
+
| command
|string
+
| string
|The command to execute
+
| The command to execute. Examples: a URL (<code>"http://cheatengine.org"</code>), an executable name (<code>"calc"</code>), a folder path (<code>"C:\"</code>), or a program/command with arguments.
 
|}
 
|}
  
 +
===Returns===
 +
Boolean — <code>true</code> if the command was successfully passed to the shell and the launch request was issued; <code>false</code> on failure. Note that a <code>true</code> return only indicates that the shell accepted the request, not that the launched program completed successfully.
 +
 +
===Description===
 +
This function calls the system shell to perform the requested action. Behavior depends on the operating system and the command supplied. On Windows typical uses include opening URLs in the default browser, launching programs, opening folders in Explorer, or starting registry editor with <code>"regedit"</code>.
 +
 +
If the string requires quoting or contains spaces, format it as you would in the Run dialog. Errors such as invalid paths, missing executables, or insufficient permissions may cause the function to return <code>false</code>.
 +
 +
===Examples===
 +
<pre>
 +
-- Open Cheat Engine website in the default browser
 +
shellExecute("http://cheatengine.org")
 +
 +
-- Launch Calculator
 +
shellExecute("calc")
 +
 +
-- Open root of C: drive in Explorer
 +
shellExecute("C:\\")
 +
 +
-- Open Registry Editor
 +
shellExecute("regedit")
 +
</pre>
 +
 +
===Notes===
 +
* The exact semantics and return value depend on the host OS. On Windows this is typically a wrapper around ShellExecute/ShellExecuteEx.
 +
* Do not pass untrusted input directly to this function if it may contain user-supplied commands (risk of command injection or unwanted program launches).
  
== See also ==
+
{{LuaSeeAlso}}
* [[Lua]]
 

Latest revision as of 18:50, 5 December 2025

<> Function

function shellExecute(command) : boolean

Executes the specified command using the operating system shell. The command can be a URL, executable name, folder path, registry editor, or any string you can use in the Windows "Run" dialog or Explorer address bar. On success the requested action (opening a URL, launching an application, opening a folder, etc.) is started.

Function Parameters[edit]

Parameter Type Description
command string The command to execute. Examples: a URL ("http://cheatengine.org"), an executable name ("calc"), a folder path ("C:\"), or a program/command with arguments.

Returns[edit]

Boolean — true if the command was successfully passed to the shell and the launch request was issued; false on failure. Note that a true return only indicates that the shell accepted the request, not that the launched program completed successfully.

Description[edit]

This function calls the system shell to perform the requested action. Behavior depends on the operating system and the command supplied. On Windows typical uses include opening URLs in the default browser, launching programs, opening folders in Explorer, or starting registry editor with "regedit".

If the string requires quoting or contains spaces, format it as you would in the Run dialog. Errors such as invalid paths, missing executables, or insufficient permissions may cause the function to return false.

Examples[edit]

-- Open Cheat Engine website in the default browser
shellExecute("http://cheatengine.org")

-- Launch Calculator
shellExecute("calc")

-- Open root of C: drive in Explorer
shellExecute("C:\\")

-- Open Registry Editor
shellExecute("regedit")

Notes[edit]

  • The exact semantics and return value depend on the host OS. On Windows this is typically a wrapper around ShellExecute/ShellExecuteEx.
  • Do not pass untrusted input directly to this function if it may contain user-supplied commands (risk of command injection or unwanted program launches).

See also[edit]

Lua
Script Engine