DllCall with ShellExecute and RunAs Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
highend
Posts: 47
Joined: 24 Nov 2014, 16:57

DllCall with ShellExecute and RunAs

Post by highend » 15 Aug 2023, 02:41

I've used this for a very long time with v1, but it doesn't work with v2 atm:

Code: Select all

DllCall("shell32.dll\ShellExecute", "UInt", 0, "Str", "RunAs", "Str", A_AhkPath, "Str", """" . A_ScriptFullPath . """", "Str", A_WorkingDir, "Int", 1)

Code: Select all

Error: Missing space or operator before this
What"s wrong with it?

User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: DllCall with ShellExecute and RunAs  Topic is solved

Post by boiler » 15 Aug 2023, 03:50

That’s not how you escape quotation marks in v2. You can either use`", which would look like "`"" inside quotation marks, or even better, use single quotes for defining the literal string so that the double quotes inside them don’t even need to be escaped: '"'. So in your code, the latter would be:

Code: Select all

DllCall("shell32.dll\ShellExecute", "UInt", 0, "Str", "RunAs", "Str", A_AhkPath, "Str", '"' . A_ScriptFullPath . '"', "Str", A_WorkingDir, "Int", 1)
(the syntax highlighting on the forum is still based on v1, so it might not look exactly as expected)

Reference: Strings/Text in Expressions

highend
Posts: 47
Joined: 24 Nov 2014, 16:57

Re: DllCall with ShellExecute and RunAs

Post by highend » 15 Aug 2023, 05:49

Thank you boiler,

after the change it works fine again

Post Reply

Return to “Ask for Help (v2)”