# HG changeset patch # User sr # Date 1541426453 -3600 # Node ID a51aaf76fd251bb680949bdc499c24da68a2734e # Parent f6b24e7b5512d663fd5c73ac2f952f010de9abfa #FEATURE by sr class: Win32OperatingSystem class added: #primShellExecuteUacElevated:args: #shellExecuteUacElevated:args: diff -r f6b24e7b5512 -r a51aaf76fd25 Win32OperatingSystem.st --- a/Win32OperatingSystem.st Mon Nov 05 14:40:55 2018 +0100 +++ b/Win32OperatingSystem.st Mon Nov 05 15:00:53 2018 +0100 @@ -4362,6 +4362,54 @@ "Created: / 15-11-2016 / 19:39:49 / cg" ! +primShellExecuteUacElevated:binary + args:args + + " + try executing binary with the highest privileges it can obtain. + this has been implement, because a normal user (from user group, not admin group) + could not write to its own HKEY_CURRENT_USER registry by Win32OperatingSystem registryEntry. + but calling a corresponding *.reg file like the following examples, did the trick (even without UAC prompt) + + self + primShellExecuteUacElevated:'regedit' asUnicode16String + args:'/s C:\users\test\desktop\add.reg' asUnicode16String + " + +%{ + int result; + + if (!__isUnicode16String(binary)) { + RETURN (false); + }; + + if (!__isUnicode16String(args)) { + RETURN (false); + }; + + result = (int)ShellExecuteW( + NULL, + // The "runas" verb is important because that's what + // internally triggers windows to open up a UAC prompt. + // windows does not always open the UAC prompt, + // if not the #binary will executed UAC elevated + L"runas", + __unicode16StringVal(binary), + __unicode16StringVal(args), + NULL, + SW_SHOWNORMAL + ); + + if (result <= 32) { + RETURN (false); + } + + RETURN (true); +%} + + "Created: / 05-11-2018 / 13:27:41 / sr" +! + shellExecute:hwndArg lpOperation:lpOperationArg lpFile:lpFileArg lpParameters:lpParametersArg lpDirectory:lpDirectoryArg nShowCmd:nShowCmd "Opens or prints the specified file, which can be an executable, document file, or directory. If its a directory, an explorer window is opened (see example below). @@ -4492,6 +4540,27 @@ " ! +shellExecuteUacElevated:binary + args:args + + " + try executing binary with the highest privileges it can obtain. + this has been implement, because a normal user (from user group, not admin group) + could not write to its own HKEY_CURRENT_USER registry by Win32OperatingSystem registryEntry. + but calling a corresponding *.reg file like the following examples, did the trick (even without UAC prompt) + + self + shellExecuteUacElevated:'regedit' + args:'/s C:\users\test\desktop\add.reg' + " + + ^ self + primShellExecuteUacElevated:binary asUnicode16String + args:args asUnicode16String + + "Created: / 05-11-2018 / 13:58:29 / sr" +! + startProcess:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream errorTo:anExternalErrStream auxFrom:anAuxiliaryStream environment:anEvironmentDictionary inDirectory:dir