diff --git a/Scalar.Common/NativeMethods.cs b/Scalar.Common/NativeMethods.cs index f9bce5c3a96..3b3b63e5b86 100644 --- a/Scalar.Common/NativeMethods.cs +++ b/Scalar.Common/NativeMethods.cs @@ -77,24 +77,6 @@ public enum FileAccess : uint GENERIC_READ = 2147483648 } - [Flags] - public enum ProcessAccessFlags : uint - { - All = 0x001F0FFF, - Terminate = 0x00000001, - CreateThread = 0x00000002, - VirtualMemoryOperation = 0x00000008, - VirtualMemoryRead = 0x00000010, - VirtualMemoryWrite = 0x00000020, - DuplicateHandle = 0x00000040, - CreateProcess = 0x000000080, - SetQuota = 0x00000100, - SetInformation = 0x00000200, - QueryInformation = 0x00000400, - QueryLimitedInformation = 0x00001000, - Synchronize = 0x00100000 - } - [Flags] public enum MoveFileFlags : uint { @@ -190,16 +172,6 @@ public static void ThrowLastWin32Exception(string message) throw new Win32Exception(Marshal.GetLastWin32Error(), message); } - [DllImport("kernel32.dll", SetLastError = true)] - public static extern SafeFileHandle OpenProcess( - ProcessAccessFlags processAccess, - bool bInheritHandle, - int processId); - - [DllImport("kernel32.dll", SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool GetExitCodeProcess(SafeFileHandle hProcess, out uint lpExitCode); - [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] private static extern SafeFileHandle CreateFile( [In] string lpFileName, diff --git a/Scalar.Common/Platforms/POSIX/POSIXPlatform.cs b/Scalar.Common/Platforms/POSIX/POSIXPlatform.cs index 1d873991645..685b5380699 100644 --- a/Scalar.Common/Platforms/POSIX/POSIXPlatform.cs +++ b/Scalar.Common/Platforms/POSIX/POSIXPlatform.cs @@ -45,20 +45,6 @@ public override bool TryVerifyAuthenticodeSignature(string path, out string subj throw new NotImplementedException(); } - public override bool IsProcessActive(int processId) - { - try - { - Process process = Process.GetProcessById(processId); - } - catch (ArgumentException) - { - return false; - } - - return true; - } - public override void IsServiceInstalledAndRunning(string name, out bool installed, out bool running) { throw new NotImplementedException(); diff --git a/Scalar.Common/Platforms/Windows/WindowsPlatform.cs b/Scalar.Common/Platforms/Windows/WindowsPlatform.cs index 10b4f8b28f0..a65f38980a9 100644 --- a/Scalar.Common/Platforms/Windows/WindowsPlatform.cs +++ b/Scalar.Common/Platforms/Windows/WindowsPlatform.cs @@ -1,5 +1,4 @@ using Microsoft.Win32; -using Microsoft.Win32.SafeHandles; using Scalar.Common; using Scalar.Common.FileSystem; using Scalar.Common.Git; @@ -203,37 +202,6 @@ public override bool IsElevated() } } - public override bool IsProcessActive(int processId) - { - using (SafeFileHandle process = NativeMethods.OpenProcess(NativeMethods.ProcessAccessFlags.QueryLimitedInformation, false, processId)) - { - if (!process.IsInvalid) - { - uint exitCode; - if (NativeMethods.GetExitCodeProcess(process, out exitCode) && exitCode == StillActive) - { - return true; - } - } - else - { - // The process.IsInvalid may be true when the process doesn't have access to call - // OpenProcess for the specified processId. Fallback to slow way of finding process. - try - { - Process.GetProcessById(processId); - return true; - } - catch (ArgumentException) - { - return false; - } - } - - return false; - } - } - public override void IsServiceInstalledAndRunning(string name, out bool installed, out bool running) { ServiceController service = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName.Equals(name, StringComparison.Ordinal)); diff --git a/Scalar.Common/ScalarPlatform.cs b/Scalar.Common/ScalarPlatform.cs index e6132d35993..8af7a652bf7 100644 --- a/Scalar.Common/ScalarPlatform.cs +++ b/Scalar.Common/ScalarPlatform.cs @@ -57,7 +57,6 @@ public static void Register(ScalarPlatform platform) /// public abstract void PrepareProcessToRunInBackground(); - public abstract bool IsProcessActive(int processId); public abstract void IsServiceInstalledAndRunning(string name, out bool installed, out bool running); public abstract string GetScalarServiceNamedPipeName(string serviceName); public abstract NamedPipeServerStream CreatePipeByName(string pipeName); diff --git a/Scalar.UnitTests/Mock/Common/MockPlatform.cs b/Scalar.UnitTests/Mock/Common/MockPlatform.cs index 366174a9680..d353c484701 100644 --- a/Scalar.UnitTests/Mock/Common/MockPlatform.cs +++ b/Scalar.UnitTests/Mock/Common/MockPlatform.cs @@ -30,8 +30,6 @@ public class MockPlatform : ScalarPlatform public override ScalarPlatformConstants Constants { get; } = new MockPlatformConstants(); - public HashSet ActiveProcesses { get; } = new HashSet(); - public override void ConfigureVisualStudio(string gitBinPath, ITracer tracer) { throw new NotSupportedException(); @@ -110,11 +108,6 @@ public override bool IsElevated() throw new NotSupportedException(); } - public override bool IsProcessActive(int processId) - { - return this.ActiveProcesses.Contains(processId); - } - public override void IsServiceInstalledAndRunning(string name, out bool installed, out bool running) { throw new NotSupportedException();