Wie kann ich dieses C# (Inside PowerShell) so ändern, dass es darauf wartet, dass der Kinderprozess, das es löst, zu beeC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Wie kann ich dieses C# (Inside PowerShell) so ändern, dass es darauf wartet, dass der Kinderprozess, das es löst, zu bee

Post by Anonymous »

Diese brillante Person JBorean93 hat ein PowerShell-Skript erstellt, das wiederum eine .exe generiert "nogui.exe" hier < /p>
Ich werde den Code zitieren, damit Sie es nicht finden müssen: < /p>
">"> ">"> ">"> ">"> ">"> ">"> ">"> ">">

Code: Select all

Add-Type -OutputType WindowsApplication -OutputAssembly NoGui.exe -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
using System.Text;

namespace NoGui
{
class Program
{
[StructLayout(LayoutKind.Sequential)]
public struct PROCESS_INFORMATION
{
public IntPtr hProcess;
public IntPtr hThread;
public int dwProcessId;
public int dwThreadId;
}

[StructLayout(LayoutKind.Sequential)]
public struct STARTUPINFOW
{
public Int32 cb;
public IntPtr lpReserved;
public IntPtr lpDesktop;
public IntPtr lpTitle;
public Int32 dwX;
public Int32 dwY;
public Int32 dwXSize;
public Int32 dwYSize;
public Int32 dwXCountChars;
public Int32 dwYCountChars;
public Int32 dwFillAttribute;
public Int32 dwFlags;
public Int16 wShowWindow;
public Int16 cbReserved2;
public IntPtr lpReserved2;
public IntPtr hStdInput;
public IntPtr hStdOutput;
public IntPtr hStdError;
}

[DllImport("Kernel32.dll", SetLastError = true)]
public static extern bool CloseHandle(
IntPtr hObject);

[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool CreateProcessW(
[MarshalAs(UnmanagedType.LPWStr)] string lpApplicationName,
StringBuilder lpCommandLine,
IntPtr lpProcessAttributes,
IntPtr lpThreadAttributes,
bool bInheritHandles,
int dwCreationFlags,
IntPtr lpEnvironment,
[MarshalAs(UnmanagedType.LPWStr)] string lpCurrentDirectory,
ref STARTUPINFOW lpStartupInfo,
out PROCESS_INFORMATION lpProcessInformation);

[DllImport("Kernel32.dll")]
public static extern IntPtr GetCommandLineW();

static void Main()
{
IntPtr cmdLinePtr = GetCommandLineW();
string cmdLine = Marshal.PtrToStringUni(cmdLinePtr);
int cmdLineArgsIdx = cmdLine.IndexOf(" -- ");
StringBuilder newCmdLine = new StringBuilder(cmdLine.Substring(cmdLineArgsIdx + 4));

STARTUPINFOW si = new STARTUPINFOW()
{
cb = Marshal.SizeOf(),
dwFlags = 0x00000001, // STARTF_USESHOWWINDOW
wShowWindow = 0, // SW_HIDE
};
PROCESS_INFORMATION pi;
bool res = CreateProcessW(
null,
newCmdLine,
IntPtr.Zero,
IntPtr.Zero,
true,
0x00000410,  // CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT
IntPtr.Zero,
null,
ref si,
out pi
);

if (res)
{
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
}
}
}
'@
Wenn nogui.exe ausgeführt wird, ermöglicht es (in meinem Anwendungsfall, PowerShell, aber es könnte jeder Prozess sein) mit absolut kein Fenster/Shell/Eingabeaufforderungen/was auch immer auf dem Bildschirm ausgeführt wird (und es funktioniert). Aber nach dem, was ich beurteilen kann, wartet es nicht auf , welcher Prozess, den Sie ihn gebeten haben, zu führen, um vor ihm zu enden, selbst, endet. Das Drehbuch, das von nogui.exe hervorgebracht wird, dauert möglicherweise lange, aber intune glaubt: "Oh, na ja, nogui.exe abgeschlossen, also muss die Installation erledigt werden." Aber es ist nicht. PowerShell -Skript explodiert aus irgendeinem Grund? Alles Gute, Intune wird der Exit -Code von nogui.exe übergeben, damit wir wissen, was passiert ist.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post