How can I make executeShell ask for Admin Elevation?

Dominikus Dittes Scherkl dominikus at scherkl.de
Tue Jul 14 08:32:09 UTC 2020


On Monday, 13 July 2020 at 19:32:33 UTC, Marcone wrote:
> alias runas = compose!(x => to!bool((cast(int) x) > 32), x => 
> ShellExecute(null, "runas", "cmd", cast(wchar*) "/c \"cd /d %s 
> && %s\"".format(getcwd(), x).to!wstring, null, 
> SW_HIDE).WaitForSingleObject(WAIT_TIMEOUT));
>
> runas("netsh winhttp set proxy 127.0.0.1:9666")

Use backticks instead of doublequotes, than you don't have to 
escape the doublequotes within the string. So:

alias runas = compose!(x => to!bool((cast(int) x) > 32), x => 
ShellExecute(null, "runas", "cmd", cast(wchar*)`/c "cd /d %s && 
%s"`.format(getcwd(), x).to!wstring, null, SW_HIDE);



More information about the Digitalmars-d-learn mailing list