Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main()
- {
- const uint NORMAL_PRIORITY_CLASS = 0x0020;
- bool retValue;
- string Application = Environment.GetEnvironmentVariable("windir") + @"\Notepad.exe";
- string CommandLine = "";
- PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();
- STARTUPINFO sInfo = new STARTUPINFO();
- SECURITY_ATTRIBUTES pSec = new SECURITY_ATTRIBUTES();
- SECURITY_ATTRIBUTES tSec = new SECURITY_ATTRIBUTES();
- pSec.nLength = Marshal.SizeOf(pSec);
- tSec.nLength = Marshal.SizeOf(tSec);
- //Open Notepad with C:\ as current directory
- string currentDirectory = @"C:\";
- retValue = CreateProcess(Application, CommandLine,
- ref pSec, ref tSec, false, NORMAL_PRIORITY_CLASS,
- IntPtr.Zero, currentDirectory, ref sInfo, out pInfo);
- Console.WriteLine("Process ID (PID): " + pInfo.dwProcessId);
- Console.WriteLine("Process Handle : " + pInfo.hProcess);
- Process p = new Process();
- p.StartInfo = new ProcessStartInfo();
- }
- [DllImport("kernel32.dll")]
- public static extern bool CreateProcess(string lpApplicationName,
- string lpCommandLine,
- ref SECURITY_ATTRIBUTES lpProcessAttributes,
- ref SECURITY_ATTRIBUTES lpThreadAttributes,
- bool bInheritHandles,
- uint dwCreationFlags,
- IntPtr lpEnvironment,
- string lpCurrentDirectory,
- [In] ref STARTUPINFO
- lpStartupInfo,
- out PROCESS_INFORMATION lpProcessInformation);
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct STARTUPINFO
- {
- public Int32 cb;
- public string lpReserved;
- public string lpDesktop;
- public string 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;
- }
- [StructLayout(LayoutKind.Sequential)]
- public struct PROCESS_INFORMATION
- {
- public IntPtr hProcess;
- public IntPtr hThread;
- public int dwProcessId;
- public int dwThreadId;
- }
- [StructLayout(LayoutKind.Sequential)]
- public struct SECURITY_ATTRIBUTES
- {
- public int nLength;
- public unsafe byte* lpSecurityDescriptor;
- public int bInheritHandle;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement