diff --git a/supporting/shimexe/bin/checksum.sha256 b/supporting/shimexe/bin/checksum.sha256 index 35742c77d4..2d7e333cf5 100644 --- a/supporting/shimexe/bin/checksum.sha256 +++ b/supporting/shimexe/bin/checksum.sha256 @@ -1 +1 @@ -dbbbea318b9216dc9671cd3902cba625dabde7c202326566ad424b9520899248 *shim.exe +cb440b8a08a2095a59666a859b35aa5a1524b140b909ecc760f38f3baccf80e6 *shim.exe diff --git a/supporting/shimexe/bin/checksum.sha512 b/supporting/shimexe/bin/checksum.sha512 index d3e9aa5c41..d75baa249a 100644 --- a/supporting/shimexe/bin/checksum.sha512 +++ b/supporting/shimexe/bin/checksum.sha512 @@ -1 +1 @@ -287b250828e1925842d52326ed93c89fb9b2451750e6d20f0db2f0406bc1a5038598f2b7b4228c8ef764f61f7c654c4aa4aef39b8ae671d457ff974ad9e4727d *shim.exe +710aeef5381f96ea0360a27ce6b792f67e018abb91d6dc67fc5c18c15baf611f36268a3f9e70a339b1a1b0e5dbfdaee10d74288352e609764d5b81303409a332 *shim.exe diff --git a/supporting/shimexe/bin/shim.exe b/supporting/shimexe/bin/shim.exe index e5e49daca2..72c5a10a0e 100644 Binary files a/supporting/shimexe/bin/shim.exe and b/supporting/shimexe/bin/shim.exe differ diff --git a/supporting/shimexe/shim.cs b/supporting/shimexe/shim.cs index d1529eaa88..1337341ef6 100644 --- a/supporting/shimexe/shim.cs +++ b/supporting/shimexe/shim.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -18,6 +19,7 @@ static extern bool CreateProcess(string lpApplicationName, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation); + const int ERROR_ELEVATION_REQUIRED = 740; [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] struct STARTUPINFO { @@ -97,7 +99,24 @@ static int Main(string[] args) { lpStartupInfo: ref si, lpProcessInformation: out pi)) { - return Marshal.GetLastWin32Error(); + var error = Marshal.GetLastWin32Error(); + if(error == ERROR_ELEVATION_REQUIRED) { + // Unfortunately, ShellExecute() does not allow us to run program without + // CREATE_NEW_CONSOLE, so we can not replace CreateProcess() completely. + // The good news is we are okay with CREATE_NEW_CONSOLE when we run program with elevation. + Process process = new Process(); + process.StartInfo = new ProcessStartInfo(path, cmd_args); + process.StartInfo.UseShellExecute = true; + try { + process.Start(); + } + catch(Win32Exception exception) { + return exception.ErrorCode; + } + process.WaitForExit(); + return process.ExitCode; + } + return error; } WaitForSingleObject(pi.hProcess, INFINITE);