Clean up '#if CORE' in ProcessCodeMethods.cs and 'ClrFacade.GetSafeProcessHandle' (#4428)

This commit is contained in:
Ilya
2017-08-08 09:20:57 -07:00
committed by Dongbo Wang
parent 0e4cd634b8
commit 649ff285ee
4 changed files with 22 additions and 39 deletions
@@ -677,7 +677,7 @@ namespace Microsoft.PowerShell.Commands
}
else if (Module.IsPresent)
{
//if only modules are to be displayed
//if only modules are to be displayed
try
{
WriteObject(process.Modules, true);
@@ -800,7 +800,7 @@ namespace Microsoft.PowerShell.Commands
do
{
int error;
if (!Win32Native.OpenProcessToken(ClrFacade.GetSafeProcessHandle(process), TOKEN_QUERY, out processTokenHandler)) { break; }
if (!Win32Native.OpenProcessToken(process.Handle, TOKEN_QUERY, out processTokenHandler)) { break; }
// Set the default length to be 256, so it will be sufficient for most cases
int tokenInfoLength = 256;
@@ -1196,7 +1196,7 @@ namespace Microsoft.PowerShell.Commands
//Addition by v-ramch Mar 18 2008
//Added force parameter
//Added force parameter
/// <summary>
/// Specifies whether to force a process to kill
/// even if it has dependent services.
@@ -1235,7 +1235,7 @@ namespace Microsoft.PowerShell.Commands
try
{
// Many properties including Name are not available if the process has exited.
// Many properties including Name are not available if the process has exited.
// If this is the case, we skip the process. If the process is from a remote
// machine, then we generate a non-terminating error because .NET doesn't support
// terminate a remote process.
@@ -1370,7 +1370,7 @@ namespace Microsoft.PowerShell.Commands
IntPtr ph = IntPtr.Zero;
try
{
if (Win32Native.OpenProcessToken(ClrFacade.GetSafeProcessHandle(process), TOKEN_QUERY, out ph))
if (Win32Native.OpenProcessToken(process.Handle, TOKEN_QUERY, out ph))
{
if (_currentUserName == null)
{
@@ -1423,7 +1423,7 @@ namespace Microsoft.PowerShell.Commands
string serviceName = oService.CimInstanceProperties["Name"].Value.ToString();
using (var service = new System.ServiceProcess.ServiceController(serviceName))
{
//try stopping the service, if cant we are not writing exception
//try stopping the service, if cant we are not writing exception
try
{
service.Stop();
@@ -1782,7 +1782,7 @@ namespace Microsoft.PowerShell.Commands
/// <summary>
/// Redirect input
/// Redirect input
/// </summary>
[Parameter(ParameterSetName = "Default")]
[Alias("RSI")]
@@ -1800,7 +1800,7 @@ namespace Microsoft.PowerShell.Commands
/// <summary>
/// Redirect output
/// Redirect output
/// </summary>
[Parameter(ParameterSetName = "Default")]
[Alias("RSO")]
@@ -1820,7 +1820,7 @@ namespace Microsoft.PowerShell.Commands
/// Verb
/// </summary>
/// <remarks>
/// The 'Verb' parameter is not supported in OneCore PowerShell
/// The 'Verb' parameter is not supported in OneCore PowerShell
/// because 'UseShellExecute' is not supported in CoreCLR.
/// </remarks>
[Parameter(ParameterSetName = "UseShellExecute")]
@@ -2155,7 +2155,7 @@ namespace Microsoft.PowerShell.Commands
#region Private Methods
/// <summary>
/// When Process exits the wait handle is set.
/// When Process exits the wait handle is set.
/// </summary>
private void myProcess_Exited(object sender, System.EventArgs e)
{
@@ -2449,7 +2449,7 @@ namespace Microsoft.PowerShell.Commands
{
lpStartupInfo.hStdError = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-12), false);
}
//STARTF_USESTDHANDLES
//STARTF_USESTDHANDLES
lpStartupInfo.dwFlags = 0x100;
int creationFlags = 0;
@@ -2529,7 +2529,7 @@ namespace Microsoft.PowerShell.Commands
}
else if (error == 0x424)
{
// The API 'CreateProcessWithLogonW' depends on the 'Secondary Logon' service, but the component 'Microsoft-Windows-SecondaryLogonService'
// The API 'CreateProcessWithLogonW' depends on the 'Secondary Logon' service, but the component 'Microsoft-Windows-SecondaryLogonService'
// is not installed in OneCoreUAP. We will get error code 0x424 when the service is not available.
message = StringUtil.Format(ProcessResources.ParameterNotSupported, "-Credential", "Start-Process");
er = new ErrorRecord(new NotSupportedException(message), "NotSupportedException", ErrorCategory.NotInstalled, null);
@@ -2607,7 +2607,7 @@ namespace Microsoft.PowerShell.Commands
ErrorRecord er = new ErrorRecord(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
ThrowTerminatingError(er);
}
return result;
return result;
}
#endif
#endregion
@@ -2621,7 +2621,7 @@ namespace Microsoft.PowerShell.Commands
internal class ProcessCollection
{
/// <summary>
/// JobObjectHandle is a reference to the job object used to track
/// JobObjectHandle is a reference to the job object used to track
/// the child processes created by the main process hosted by the Start-Process cmdlet.
/// </summary>
private Microsoft.PowerShell.Commands.SafeJobHandle _jobObjectHandle;
@@ -2636,7 +2636,7 @@ namespace Microsoft.PowerShell.Commands
}
/// <summary>
/// Start API assigns the process to the JobObject and starts monitoring
/// Start API assigns the process to the JobObject and starts monitoring
/// the child processes hosted by the process created by Start-Process cmdlet.
/// </summary>
internal bool AssignProcessToJobObject(Process process)
@@ -2688,8 +2688,8 @@ namespace Microsoft.PowerShell.Commands
}
/// <summary>
/// JOBOBJECT_BASIC_PROCESS_ID_LIST Contains the process identifier list for a job object.
/// If the job is nested, the process identifier list consists of all
/// JOBOBJECT_BASIC_PROCESS_ID_LIST Contains the process identifier list for a job object.
/// If the job is nested, the process identifier list consists of all
/// processes associated with the job and its child jobs.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
@@ -2701,14 +2701,14 @@ namespace Microsoft.PowerShell.Commands
public uint NumberOfAssignedProcess;
/// <summary>
/// The number of process identifiers returned in the ProcessIdList buffer.
/// If this number is less than NumberOfAssignedProcesses, increase
/// The number of process identifiers returned in the ProcessIdList buffer.
/// If this number is less than NumberOfAssignedProcesses, increase
/// the size of the buffer to accommodate the complete list.
/// </summary>
public uint NumberOfProcessIdsInList;
/// <summary>
/// A variable-length array of process identifiers returned by this call.
/// A variable-length array of process identifiers returned by this call.
/// Array elements 0 through NumberOfProcessIdsInList minus 1
/// contain valid process identifiers.
/// </summary>
@@ -58,11 +58,8 @@ namespace Microsoft.PowerShell {
Diagnostics.Assert(process != null, "Ensure process is not null before calling");
PROCESS_BASIC_INFORMATION pbi;
int size;
#if CORECLR
var res = NtQueryInformationProcess(process.SafeHandle.DangerousGetHandle(), 0, out pbi, Marshal.SizeOf<PROCESS_BASIC_INFORMATION>(), out size);
#else
var res = NtQueryInformationProcess(process.Handle, 0, out pbi, Marshal.SizeOf<PROCESS_BASIC_INFORMATION>(), out size);
#endif
return res != 0 ? InvalidProcessId : pbi.InheritedFromUniqueProcessId.ToInt32();
}
@@ -140,7 +140,7 @@ namespace Microsoft.PowerShell.Commands.Internal
[ResourceExposure(ResourceScope.Machine)]
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool OpenProcessToken(SafeHandle processHandle, uint desiredAccess, out IntPtr tokenHandle);
internal static extern bool OpenProcessToken(IntPtr processHandle, uint desiredAccess, out IntPtr tokenHandle);
/// <summary>
/// The GetTokenInformation function retrieves a specified type of information about an access token.
@@ -47,20 +47,6 @@ namespace System.Management.Automation
/// </summary>
internal static readonly char FIRST_CHAR_PSASSEMBLY_MARK = (char)0x29f9;
#region Process
/// <summary>
/// Facade for Process.Handle to get SafeHandle
/// </summary>
/// <param name="process"></param>
/// <returns>SafeHandle</returns>
internal static SafeHandle GetSafeProcessHandle(Process process)
{
return process.SafeHandle;
}
#endregion Process
#region Assembly
internal static IEnumerable<Assembly> GetAssemblies(TypeResolutionState typeResolutionState, TypeName typeName)