Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ private static extern uint PdhExpandWildCardPathH(PdhSafeDataSourceHandle hDataS
private static extern uint PdhValidatePath(string szFullPathBuffer);

[DllImport("pdh.dll", CharSet = CharSet.Unicode)]
private static extern uint PdhGetCounterInfo(IntPtr hCounter, [MarshalAs(UnmanagedType.U1)]bool bRetrieveExplainText, ref IntPtr pdwBufferSize, IntPtr lpBuffer);
private static extern uint PdhGetCounterInfo(IntPtr hCounter, [MarshalAs(UnmanagedType.U1)] bool bRetrieveExplainText, ref IntPtr pdwBufferSize, IntPtr lpBuffer);

[DllImport("pdh.dll", CharSet = CharSet.Unicode)]
private static extern uint PdhGetCounterTimeBase(IntPtr hCounter, out UInt64 pTimeBase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2351,82 +2351,82 @@ private static byte[] ConvertEnvVarsToByteArray(StringDictionary sd)

private void SetStartupInfo(ProcessStartInfo startinfo, ref ProcessNativeMethods.STARTUPINFO lpStartupInfo, ref int creationFlags)
{
// RedirectionStandardInput
if (_redirectstandardinput != null)
{
startinfo.RedirectStandardInput = true;
_redirectstandardinput = ResolveFilePath(_redirectstandardinput);
lpStartupInfo.hStdInput = GetSafeFileHandleForRedirection(_redirectstandardinput, ProcessNativeMethods.OPEN_EXISTING);
}
else
{
lpStartupInfo.hStdInput = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-10), false);
}
// RedirectionStandardInput
if (_redirectstandardinput != null)
{
startinfo.RedirectStandardInput = true;
_redirectstandardinput = ResolveFilePath(_redirectstandardinput);
lpStartupInfo.hStdInput = GetSafeFileHandleForRedirection(_redirectstandardinput, ProcessNativeMethods.OPEN_EXISTING);
}
else
{
lpStartupInfo.hStdInput = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-10), false);
}

// RedirectionStandardOutput
if (_redirectstandardoutput != null)
{
startinfo.RedirectStandardOutput = true;
_redirectstandardoutput = ResolveFilePath(_redirectstandardoutput);
lpStartupInfo.hStdOutput = GetSafeFileHandleForRedirection(_redirectstandardoutput, ProcessNativeMethods.CREATE_ALWAYS);
}
else
{
lpStartupInfo.hStdOutput = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-11), false);
}
// RedirectionStandardOutput
if (_redirectstandardoutput != null)
{
startinfo.RedirectStandardOutput = true;
_redirectstandardoutput = ResolveFilePath(_redirectstandardoutput);
lpStartupInfo.hStdOutput = GetSafeFileHandleForRedirection(_redirectstandardoutput, ProcessNativeMethods.CREATE_ALWAYS);
}
else
{
lpStartupInfo.hStdOutput = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-11), false);
}

// RedirectionStandardError
if (_redirectstandarderror != null)
{
startinfo.RedirectStandardError = true;
_redirectstandarderror = ResolveFilePath(_redirectstandarderror);
lpStartupInfo.hStdError = GetSafeFileHandleForRedirection(_redirectstandarderror, ProcessNativeMethods.CREATE_ALWAYS);
}
else
{
lpStartupInfo.hStdError = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-12), false);
}
// RedirectionStandardError
if (_redirectstandarderror != null)
{
startinfo.RedirectStandardError = true;
_redirectstandarderror = ResolveFilePath(_redirectstandarderror);
lpStartupInfo.hStdError = GetSafeFileHandleForRedirection(_redirectstandarderror, ProcessNativeMethods.CREATE_ALWAYS);
}
else
{
lpStartupInfo.hStdError = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-12), false);
}

// STARTF_USESTDHANDLES
lpStartupInfo.dwFlags = 0x100;
// STARTF_USESTDHANDLES
lpStartupInfo.dwFlags = 0x100;

if (startinfo.CreateNoWindow)
{
// No new window: Inherit the parent process's console window
creationFlags = 0x00000000;
}
else
{
// CREATE_NEW_CONSOLE
creationFlags |= 0x00000010;
if (startinfo.CreateNoWindow)
{
// No new window: Inherit the parent process's console window
creationFlags = 0x00000000;
}
else
{
// CREATE_NEW_CONSOLE
creationFlags |= 0x00000010;

// STARTF_USESHOWWINDOW
lpStartupInfo.dwFlags |= 0x00000001;
// STARTF_USESHOWWINDOW
lpStartupInfo.dwFlags |= 0x00000001;

// On headless SKUs like NanoServer and IoT, window style can only be the default value 'Normal'.
switch (startinfo.WindowStyle)
{
case ProcessWindowStyle.Normal:
// SW_SHOWNORMAL
lpStartupInfo.wShowWindow = 1;
break;
case ProcessWindowStyle.Minimized:
// SW_SHOWMINIMIZED
lpStartupInfo.wShowWindow = 2;
break;
case ProcessWindowStyle.Maximized:
// SW_SHOWMAXIMIZED
lpStartupInfo.wShowWindow = 3;
break;
case ProcessWindowStyle.Hidden:
// SW_HIDE
lpStartupInfo.wShowWindow = 0;
break;
}
// On headless SKUs like NanoServer and IoT, window style can only be the default value 'Normal'.
switch (startinfo.WindowStyle)
{
case ProcessWindowStyle.Normal:
// SW_SHOWNORMAL
lpStartupInfo.wShowWindow = 1;
break;
case ProcessWindowStyle.Minimized:
// SW_SHOWMINIMIZED
lpStartupInfo.wShowWindow = 2;
break;
case ProcessWindowStyle.Maximized:
// SW_SHOWMAXIMIZED
lpStartupInfo.wShowWindow = 3;
break;
case ProcessWindowStyle.Hidden:
// SW_HIDE
lpStartupInfo.wShowWindow = 0;
break;
}
}

// Create the new process suspended so we have a chance to get a corresponding Process object in case it terminates quickly.
creationFlags |= 0x00000004;
// Create the new process suspended so we have a chance to get a corresponding Process object in case it terminates quickly.
creationFlags |= 0x00000004;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public sealed class UnmanagedPSEntry
/// Length of the passed in argument array.
/// </param>
[Obsolete("Callers should now use UnmanagedPSEntry.Start(string[], int)", error: true)]
public static int Start(string consoleFilePath, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 2)]string[] args, int argc)
public static int Start(string consoleFilePath, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 2)] string[] args, int argc)
{
return Start(args, argc);
}
Expand All @@ -47,7 +47,7 @@ public static int Start(string consoleFilePath, [MarshalAs(UnmanagedType.LPArray
/// <param name="argc">
/// Length of the passed in argument array.
/// </param>
public static int Start([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)]string[] args, int argc)
public static int Start([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] string[] args, int argc)
{
if (args == null)
{
Expand Down
Loading