1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

When Run doesn't work, try ShellExecute

Last updated at Posted at 2012-02-10

Sometimes the Run command does not work. In that case, the ShellExecute API function is worth trying.

shellexecute.ahk
strFilePath := A_WinDir "\notepad.exe"
if (ErrorCode := ShellExecute(strFilePath)) <= 32
	msgbox % ErrorCode

ShellExecute(strFilePath, strArgs="", nShowCmd=1) {
	;http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx
	HINSTANCE := DllCall(A_IsUnicode ? "shell32\ShellExecuteW" : "shell32\ShellExecuteA"
	   , ptr ? ptr : "uint", 0
	   , "uint", 0
	   , "str", strFilePath
	   , "str", strArgs  ; arguments
	   , "uint", 0
	   , "int", nShowCmd	; specifies how an application is to be displayed when it is opened
	   , ptr ? ptr : "uint" )
	Return HINSTANCE
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?