Skip to content

Commit

Permalink
Enabled applications which require elevated privileges. (ScoopInstall…
Browse files Browse the repository at this point in the history
  • Loading branch information
excitoon authored and Richard Kuhnt committed Mar 13, 2018
1 parent 4ab506f commit 2d9f964
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion supporting/shimexe/bin/checksum.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dbbbea318b9216dc9671cd3902cba625dabde7c202326566ad424b9520899248 *shim.exe
cb440b8a08a2095a59666a859b35aa5a1524b140b909ecc760f38f3baccf80e6 *shim.exe
2 changes: 1 addition & 1 deletion supporting/shimexe/bin/checksum.sha512
Original file line number Diff line number Diff line change
@@ -1 +1 @@
287b250828e1925842d52326ed93c89fb9b2451750e6d20f0db2f0406bc1a5038598f2b7b4228c8ef764f61f7c654c4aa4aef39b8ae671d457ff974ad9e4727d *shim.exe
710aeef5381f96ea0360a27ce6b792f67e018abb91d6dc67fc5c18c15baf611f36268a3f9e70a339b1a1b0e5dbfdaee10d74288352e609764d5b81303409a332 *shim.exe
Binary file modified supporting/shimexe/bin/shim.exe
Binary file not shown.
21 changes: 20 additions & 1 deletion supporting/shimexe/shim.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand All @@ -18,6 +19,7 @@ class Program {
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 {
Expand Down Expand Up @@ -97,7 +99,24 @@ internal struct PROCESS_INFORMATION {
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);
Expand Down

0 comments on commit 2d9f964

Please sign in to comment.