AutoHotKey Run Windows Commands

run, %comspec% /c del C:\Users\Test\Desktop\test.txt,,hide

%comspec% points to cmd.exe if you need to run as admin, you'll want to look at runas.


You don't have to use %ComSpec% as pointed by the other answer. You can use cmd.exe and use /c which is the command indicator, it will run anything in front of it, inside cmd.

Run cmd.exe /c del C:\Users\Test\Desktop\test.txt

Here's how the syntax of it looks like:

Run, Target, WorkingDir, Options, OutputVarPID

RunWait, Target, WorkingDir, Options, OutputVarPID

If you need for a command to finish and then continue, use RunWait. To save the output of a command, for example if you want to save your WAN IP address in your clipboard, you can pipe the output with the clip command.

RunWait, cmd.exe /c nslookup myip.opendns.com resolver1.opendns.com | clip

If you need a one line answer, you can use the find command to remove unwanted lines:

RunWait, cmd.exe /c nslookup myip.opendns.com resolver1.opendns.com | find /i "address" | find /v "208.67.222.222" | clip

You can hide the cmd window from showing up with the option hide:

Run cmd.exe /c del C:\Users\Test\Desktop\test.txt,,hide


https://www.autohotkey.com/docs/commands/Run.htm