Skip to content

Commit 2d9f964

Browse files
excitoonr15ch13
authored andcommitted
Enabled applications which require elevated privileges. (#2053)
1 parent 4ab506f commit 2d9f964

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dbbbea318b9216dc9671cd3902cba625dabde7c202326566ad424b9520899248 *shim.exe
1+
cb440b8a08a2095a59666a859b35aa5a1524b140b909ecc760f38f3baccf80e6 *shim.exe
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
287b250828e1925842d52326ed93c89fb9b2451750e6d20f0db2f0406bc1a5038598f2b7b4228c8ef764f61f7c654c4aa4aef39b8ae671d457ff974ad9e4727d *shim.exe
1+
710aeef5381f96ea0360a27ce6b792f67e018abb91d6dc67fc5c18c15baf611f36268a3f9e70a339b1a1b0e5dbfdaee10d74288352e609764d5b81303409a332 *shim.exe

supporting/shimexe/bin/shim.exe

512 Bytes
Binary file not shown.

supporting/shimexe/shim.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Collections.Generic;
34
using System.Diagnostics;
45
using System.IO;
@@ -18,6 +19,7 @@ static extern bool CreateProcess(string lpApplicationName,
1819
uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,
1920
[In] ref STARTUPINFO lpStartupInfo,
2021
out PROCESS_INFORMATION lpProcessInformation);
22+
const int ERROR_ELEVATION_REQUIRED = 740;
2123

2224
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
2325
struct STARTUPINFO {
@@ -97,7 +99,24 @@ static int Main(string[] args) {
9799
lpStartupInfo: ref si,
98100
lpProcessInformation: out pi)) {
99101

100-
return Marshal.GetLastWin32Error();
102+
var error = Marshal.GetLastWin32Error();
103+
if(error == ERROR_ELEVATION_REQUIRED) {
104+
// Unfortunately, ShellExecute() does not allow us to run program without
105+
// CREATE_NEW_CONSOLE, so we can not replace CreateProcess() completely.
106+
// The good news is we are okay with CREATE_NEW_CONSOLE when we run program with elevation.
107+
Process process = new Process();
108+
process.StartInfo = new ProcessStartInfo(path, cmd_args);
109+
process.StartInfo.UseShellExecute = true;
110+
try {
111+
process.Start();
112+
}
113+
catch(Win32Exception exception) {
114+
return exception.ErrorCode;
115+
}
116+
process.WaitForExit();
117+
return process.ExitCode;
118+
}
119+
return error;
101120
}
102121

103122
WaitForSingleObject(pi.hProcess, INFINITE);

0 commit comments

Comments
 (0)