Skip to content

Portable Tool for an Ideal Windows Setup

fix stale PID causes crash on elevated tweaks (#130)

Yayo Razofc9167aa6caa
diff --git a/.Source/GTweak/Utilities/Helpers/TrustedInstaller.cs b/.Source/GTweak/Utilities/Helpers/TrustedInstaller.cs
index c5045ac6..5fd1dcc6 100644
--- a/.Source/GTweak/Utilities/Helpers/TrustedInstaller.cs
+++ b/.Source/GTweak/Utilities/Helpers/TrustedInstaller.cs
@@ -153,6 +153,19 @@ namespace GTweak.Utilities.Helpers
Synchronize = 0x00100000
}
+ private static bool IsProcessRunning(int processId)
+ {
+ try
+ {
+ using Process process = Process.GetProcessById(processId);
+ return !process.HasExited;
+ }
+ catch (ArgumentException)
+ {
+ return false;
+ }
+ }
+
private static bool ImpersonateSystem()
{
IntPtr tokenHandle = IntPtr.Zero;
@@ -269,6 +282,12 @@ namespace GTweak.Utilities.Helpers
throw new Win32Exception("Failed to impersonate SYSTEM identity");
}
+ if (!IsProcessRunning(parentProcessId))
+ {
+ StartTrustedInstallerService();
+ parentProcessId = CommandExecutor.PID;
+ }
+
attributeList = Marshal.AllocHGlobal((IntPtr)(long)lpSize);
if (!InitializeProcThreadAttributeList(attributeList, 1, 0, ref lpSize))