maestrith / AHK-Studio

Created with AHK Studio
http://www.maestrith.com
363 stars 68 forks source link

Make Run_As() slightly more robust #243

Open Lexikos opened 2 years ago

Lexikos commented 2 years ago

Adding quote marks and the filename extension eliminates ambiguity, which is important due to how CreateProcess parses the command line:

The system tries to interpret the possibilities in the following order:

  • c:\program.exe
  • c:\program files\sub.exe
  • c:\program files\sub dir\program.exe
  • c:\program files\sub dir\program name.exe

If CreateProcess fails, Run relies on the the quote marks and/or filename extension to split the command line into "action" and "params", which are shown in the error message after attempting ShellExecuteEx; but that only matters if CreateProcess fails.

(In my case, the ambiguity was a red herring, and the root issue was that "Run As" simply doesn't work for untitled files that have not been saved.)