public void TestMethod() { using (var hsnap = CreateToolhelp32Snapshot(TH32CS.TH32CS_SNAPPROCESS, 0)) { if (hsnap.IsInvalid) { Assert.Fail(Win32Error.GetLastError().ToString()); } var pe = new PROCESSENTRY32 { dwSize = (uint)Marshal.SizeOf(typeof(PROCESSENTRY32)) }; if (!Process32First(hsnap, ref pe)) { Assert.Fail(Win32Error.GetLastError().ToString()); } do { TestContext.WriteLine("======================================="); TestContext.WriteLine($"PROCESS NAME: {pe.szExeFile}"); TestContext.WriteLine("---------------------------------------"); CREATE_PROCESS pClass = 0; using (var hproc = OpenProcess((uint)ProcessAccess.PROCESS_ALL_ACCESS, false, pe.th32ProcessID)) { if (!hproc.IsInvalid) { pClass = GetPriorityClass(hproc); } } TestContext.WriteLine($"Process ID: {pe.th32ProcessID}"); TestContext.WriteLine($"Thread count: {pe.cntThreads}"); TestContext.WriteLine($"Parent process ID: {pe.th32ParentProcessID}"); TestContext.WriteLine($"Priority base: {pe.pcPriClassBase}"); TestContext.WriteLine($"Priority class: {pClass}"); TestContext.WriteLine(); } while (Process32Next(hsnap, ref pe)); } }
public static extern bool CreateProcess( [In] [MarshalAs(UnmanagedType.LPTStr)] string lpApplicationName, IntPtr lpCommandLine, [In] ref SECURITY_ATTRIBUTES lpProcessAttributes, [In] ref SECURITY_ATTRIBUTES lpThreadAttributes, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandles, CREATE_PROCESS dwCreationFlags, [In] IntPtr lpEnvironment, [In] [MarshalAs(UnmanagedType.LPTStr)] string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, [Out] out PROCESS_INFORMATION lpProcessInformation);
public static extern bool CreateProcessAsUser(HTOKEN hToken, [Optional] string lpApplicationName, [Optional] StringBuilder lpCommandLine, [Optional] SECURITY_ATTRIBUTES lpProcessAttributes, [Optional] SECURITY_ATTRIBUTES lpThreadAttributes, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandles, CREATE_PROCESS dwCreationFlags, [Optional] IntPtr lpEnvironment, [Optional] string lpCurrentDirectory, in STARTUPINFO lpStartupInfo, [Out] PROCESS_INFORMATION lpProcessInformation);