Skip to content

Commit

Permalink
[System] Import System.Diagnostics.Process
Browse files Browse the repository at this point in the history
  • Loading branch information
luhenry committed Feb 12, 2016
1 parent f74f703 commit cba671a
Show file tree
Hide file tree
Showing 17 changed files with 624 additions and 1,377 deletions.
11 changes: 11 additions & 0 deletions mcs/class/System/ReferenceSources/EnvironmentHelpers.cs
@@ -0,0 +1,11 @@

namespace System
{
internal static class EnvironmentHelpers
{
internal static bool IsWindowsVistaOrAbove()
{
return true;
}
}
}
209 changes: 205 additions & 4 deletions mcs/class/System/ReferenceSources/NativeMethods.cs
@@ -1,7 +1,208 @@

using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;

namespace Microsoft.Win32
{
static class NativeMethods
{
public const int E_ABORT = unchecked ((int)0x80004004);
}
static class NativeMethods
{
public const int E_ABORT = unchecked ((int)0x80004004);

public const int PROCESS_TERMINATE = 0x0001;
public const int PROCESS_CREATE_THREAD = 0x0002;
public const int PROCESS_SET_SESSIONID = 0x0004;
public const int PROCESS_VM_OPERATION = 0x0008;
public const int PROCESS_VM_READ = 0x0010;
public const int PROCESS_VM_WRITE = 0x0020;
public const int PROCESS_DUP_HANDLE = 0x0040;
public const int PROCESS_CREATE_PROCESS = 0x0080;
public const int PROCESS_SET_QUOTA = 0x0100;
public const int PROCESS_SET_INFORMATION = 0x0200;
public const int PROCESS_QUERY_INFORMATION = 0x0400;
public const int PROCESS_QUERY_LIMITED_INFORMATION = 0x1000;
public const int STANDARD_RIGHTS_REQUIRED = 0x000F0000;
public const int SYNCHRONIZE = 0x00100000;
public const int PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFF;

public const int DUPLICATE_CLOSE_SOURCE = 1;
public const int DUPLICATE_SAME_ACCESS = 2;

public const int STILL_ACTIVE = 0x00000103;

public const int WAIT_OBJECT_0 = 0x00000000;
public const int WAIT_FAILED = unchecked((int)0xFFFFFFFF);
public const int WAIT_TIMEOUT = 0x00000102;
public const int WAIT_ABANDONED = 0x00000080;
public const int WAIT_ABANDONED_0 = WAIT_ABANDONED;

public static bool DuplicateHandle(HandleRef hSourceProcessHandle, SafeHandle hSourceHandle, HandleRef hTargetProcess,
out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions)
{
bool release = false;
try {
hSourceHandle.DangerousAddRef (ref release);

MonoIOError error;
IntPtr nakedTargetHandle;
bool ret = MonoIO.DuplicateHandle (hSourceProcessHandle.Handle, hSourceHandle.DangerousGetHandle (), hTargetProcess.Handle,
out nakedTargetHandle, dwDesiredAccess, bInheritHandle ? 1 : 0, dwOptions, out error);

if (error != MonoIOError.ERROR_SUCCESS)
throw MonoIO.GetException (error);

targetHandle = new SafeWaitHandle (nakedTargetHandle, true);
return ret;
} finally {
if (release)
hSourceHandle.DangerousRelease ();
}
}

public static bool DuplicateHandle(HandleRef hSourceProcessHandle, HandleRef hSourceHandle, HandleRef hTargetProcess,
out SafeProcessHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions)
{
MonoIOError error;
IntPtr nakedTargetHandle;
bool ret = MonoIO.DuplicateHandle (hSourceProcessHandle.Handle, hSourceHandle.Handle, hTargetProcess.Handle,
out nakedTargetHandle, dwDesiredAccess, bInheritHandle ? 1 : 0, dwOptions, out error);

if (error != MonoIOError.ERROR_SUCCESS)
throw MonoIO.GetException (error);

targetHandle = new SafeProcessHandle (nakedTargetHandle, true);
return ret;
}

[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern IntPtr GetCurrentProcess();

[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern bool GetExitCodeProcess (IntPtr processHandle, out int exitCode);

public static bool GetExitCodeProcess (SafeProcessHandle processHandle, out int exitCode)
{
bool release = false;
try {
processHandle.DangerousAddRef (ref release);
return GetExitCodeProcess (processHandle.DangerousGetHandle (), out exitCode);
} finally {
if (release)
processHandle.DangerousRelease ();
}
}

[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern bool TerminateProcess (IntPtr processHandle, int exitCode);

public static bool TerminateProcess (SafeProcessHandle processHandle, int exitCode)
{
bool release = false;
try {
processHandle.DangerousAddRef (ref release);
return TerminateProcess (processHandle.DangerousGetHandle (), exitCode);
} finally {
if (release)
processHandle.DangerousRelease ();
}
}

[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern int WaitForInputIdle (IntPtr handle, int milliseconds);

public static int WaitForInputIdle (SafeProcessHandle handle, int milliseconds)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return WaitForInputIdle (handle.DangerousGetHandle (), milliseconds);
} finally {
if (release)
handle.DangerousRelease ();
}
}

[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern bool GetProcessWorkingSetSize (IntPtr handle, out IntPtr min, out IntPtr max);

public static bool GetProcessWorkingSetSize (SafeProcessHandle handle, out IntPtr min, out IntPtr max)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return GetProcessWorkingSetSize (handle.DangerousGetHandle (), out min, out max);
} finally {
if (release)
handle.DangerousRelease ();
}
}

[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern bool SetProcessWorkingSetSize (IntPtr handle, IntPtr min, IntPtr max);

public static bool SetProcessWorkingSetSize (SafeProcessHandle handle, IntPtr min, IntPtr max)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return SetProcessWorkingSetSize (handle.DangerousGetHandle (), min, max);
} finally {
if (release)
handle.DangerousRelease ();
}
}

[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern bool GetProcessTimes (IntPtr handle, out long creation, out long exit, out long kernel, out long user);

public static bool GetProcessTimes (SafeProcessHandle handle, out long creation, out long exit, out long kernel, out long user)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return GetProcessTimes (handle.DangerousGetHandle (), out creation, out exit, out kernel, out user);
} finally {
if (release)
handle.DangerousRelease ();
}
}

[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern int GetCurrentProcessId ();

[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern int GetPriorityClass (IntPtr handle);

public static int GetPriorityClass(SafeProcessHandle handle)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return GetPriorityClass (handle.DangerousGetHandle ());
} finally {
if (release)
handle.DangerousRelease ();
}
}

[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern bool SetPriorityClass (IntPtr handle, int priorityClass);

public static bool SetPriorityClass(SafeProcessHandle handle, int priorityClass)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return SetPriorityClass (handle.DangerousGetHandle (), priorityClass);
} finally {
if (release)
handle.DangerousRelease ();
}
}

[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern static bool CloseProcess (IntPtr handle);
}
}
87 changes: 87 additions & 0 deletions mcs/class/System/ReferenceSources/SR.cs
Expand Up @@ -926,4 +926,91 @@ public static object GetObject (string name)
public const string InvalidLanguageIdentifier = @"The identifier:""{0}"" on the property:""{1}"" of type:""{2}"" is not a valid language-independent identifier name. Check to see if CodeGenerator.IsValidLanguageIndependentIdentifier allows the identifier name.";
public const string InvalidTypeName = @"The type name:""{0}"" on the property:""{1}"" of type:""{2}"" is not a valid language-independent type name.";
public const string InvalidRegion = "The region directive '{0}' contains invalid characters. RegionText cannot contain any new line characters.";

public const string BadMaxWorkset = "Maximum working set size is invalid. It must be greater than or equal to the minimum working set size.";
public const string BadMinWorkset = "Minimum working set size is invalid. It must be less than or equal to the maximum working set size.";
public const string CantGetStandardError = "StandardError has not been redirected.";
public const string CantGetStandardIn = "StandardIn has not been redirected.";
public const string CantGetStandardOut = "StandardOut has not been redirected or the process hasn't started yet.";
public const string CantMixSyncAsyncOperation = "Cannot mix synchronous and asynchronous operation on process stream.";
public const string CantRedirectStreams = "The Process object must have the UseShellExecute property set to false in order to redirect IO streams.";
public const string CantStartAsUser = "The Process object must have the UseShellExecute property set to false in order to start a process as a user.";
public const string CantUseEnvVars = "The Process object must have the UseShellExecute property set to false in order to use environment variables.";
public const string EnvironmentBlockTooLong = "The environment block used to start a process cannot be longer than 65535 bytes. Your environment block is {0} bytes long. Remove some environment variables and try again.";
public const string FileNameMissing = "Cannot start process because a file name has not been provided.";
public const string InputIdleUnkownError = "WaitForInputIdle failed. This could be because the process does not have a graphical interface.";
public const string NoAssociatedProcess = "No process is associated with this object.";
public const string NoAsyncOperation = "No async read operation is in progress on the stream.";
public const string NoProcessHandle = "Process was not started by this object, so requested information cannot be determined.";
public const string NoProcessInfo = "Process has exited, so the requested information is not available.";
public const string NotSupportedRemote = "Feature is not supported for remote machines.";
public const string PendingAsyncOperation = "An async read operation has already been started on the stream.";
public const string PriorityClassNotSupported = "The AboveNormal and BelowNormal priority classes are not available on this platform.";
public const string ProcessArguments = "Command line arguments that will be passed to the application specified by the FileName property.";
public const string ProcessAssociated = "Indicates if the process component is associated with a real process.";
public const string ProcessBasePriority = "The base priority computed based on the priority class that all threads run relative to.";
public const string ProcessCreateNoWindow = "Whether to start the process without creating a new window to contain it.";
public const string ProcessDesc = "Provides access to local and remote processes, enabling starting and stopping of local processes.";
public const string ProcessEnableRaisingEvents = "Whether the process component should watch for the associated process to exit, and raise the Exited event.";
public const string ProcessEnvironmentVariables = "Set of environment variables that apply to this process and child processes.";
public const string ProcessErrorDialog = "Whether to show an error dialog to the user if there is an error.";
public const string ProcessExitCode = "The value returned from the associated process when it terminated.";
public const string ProcessExited = "If the WatchForExit property is set to true, then this event is raised when the associated process exits.";
public const string ProcessExitTime = "The time that the associated process exited.";
public const string ProcessFileName = "The name of the application, document or URL to start.";
public const string ProcessHandle = "Returns the native handle for this process. The handle is only available if the process was started using this component.";
public const string ProcessHandleCount = "The number of native handles associated with this process.";
public const string ProcessHasExited = "Cannot process request because the process ({0}) has exited.";
public const string ProcessHasExitedNoId = "Cannot process request because the process has exited.";
public const string ProcessId = "The unique identifier for the process.";
public const string ProcessIdRequired = "Feature requires a process identifier.";
public const string ProcessMachineName = "The name of the machine the running the process.";
public const string ProcessMainModule = "The main module for the associated process.";
public const string ProcessMainWindowHandle = "The handle of the main window for the process.";
public const string ProcessMainWindowTitle = "The caption of the main window for the process.";
public const string ProcessMaxWorkingSet = "The maximum amount of physical memory the process has required since it was started.";
public const string ProcessMinWorkingSet = "The minimum amount of physical memory the process has required since it was started.";
public const string ProcessModules = "The modules that have been loaded by the associated process.";
public const string ProcessNonpagedSystemMemorySize = "The number of bytes of non pageable system memory the process is using.";
public const string ProcessPagedMemorySize = "The current amount of memory that can be paged to disk that the process is using.";
public const string ProcessPagedSystemMemorySize = "The number of bytes of pageable system memory the process is using.";
public const string ProcessPeakPagedMemorySize = "The maximum amount of memory that can be paged to disk that the process has used since it was started.";
public const string ProcessPeakVirtualMemorySize = "The maximum amount of virtual memory the process has allocated since it was started.";
public const string ProcessPeakWorkingSet = "The maximum amount of physical memory the process has used since it was started.";
public const string ProcessPriorityBoostEnabled = "Whether this process would like a priority boost when the user interacts with it.";
public const string ProcessPriorityClass = "The priority that the threads in the process run relative to.";
public const string ProcessPrivateMemorySize = "The current amount of memory that the process has allocated that cannot be shared with other processes.";
public const string ProcessPrivilegedProcessorTime = "The amount of CPU time the process spent inside the operating system core.";
public const string ProcessProcessName = "The name of the process.";
public const string ProcessProcessorAffinity = "A bit mask which represents the processors that the threads within the process are allowed to run on.";
public const string ProcessRedirectStandardError = "Whether the process's error output is written to the Process instance's StandardError member.";
public const string ProcessRedirectStandardInput = "Whether the process command input is read from the Process instance's StandardInput member.";
public const string ProcessRedirectStandardOutput = "Whether the process output is written to the Process instance's StandardOutput member.";
public const string ProcessResponding = "Whether this process is currently responding.";
public const string ProcessSessionId = "The identifier for the session of the process.";
public const string ProcessStandardError = "Standard error stream of the process.";
public const string ProcessStandardInput = "Standard input stream of the process.";
public const string ProcessStandardOutput = "Standard output stream of the process.";
public const string ProcessStartInfo = "Specifies information used to start a process.";
public const string ProcessStartTime = "The time at which the process was started.";
public const string ProcessSynchronizingObject = "The object used to marshal the event handler calls issued as a result of a Process exit.";
public const string ProcessTerminated = "Indicates if the associated process has been terminated.";
public const string ProcessThreads = "The threads running in the associated process.";
public const string ProcessTotalProcessorTime = "The amount of CPU time the process has used.";
public const string ProcessUserProcessorTime = "The amount of CPU time the process spent outside the operating system core.";
public const string ProcessUseShellExecute = "Whether to use the operating system shell to start the process.";
public const string ProcessVerb = "The verb to apply to the document specified by the FileName property.";
public const string ProcessVirtualMemorySize = "The amount of virtual memory the process has currently allocated.";
public const string ProcessWindowStyle = "How the main window should be created when the process starts.";
public const string ProcessWorkingDirectory = "The initial working directory for the process.";
public const string ProcessWorkingSet = "The current amount of physical memory the process is using.";
public const string ProcModBaseAddress = "The memory address that the module loaded at.";
public const string ProcModEntryPointAddress = "The memory address of the function that runs when the module is loaded.";
public const string ProcModFileName = "The file name of the module.";
public const string ProcModModuleMemorySize = "The amount of virtual memory required by the code and data in the module file.";
public const string ProcModModuleName = "The name of the module.";
public const string StandardErrorEncodingNotAllowed = "StandardErrorEncoding is only supported when standard error is redirected.";
public const string StandardOutputEncodingNotAllowed = "StandardOutputEncoding is only supported when standard output is redirected.";
public const string WaitTillExit = "Process must exit before requested information can be determined.";
public const string Win2kRequired = "Feature requires Windows 2000.";
}

0 comments on commit cba671a

Please sign in to comment.