Exemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="processInformation"></param>
 public PROCESS_INFORMATION(PROCESS_INFORMATION processInformation) : this()
 {
     ProcessId = processInformation.ProcessId;
     ThreadId  = processInformation.ThreadId;
     hProcess  = MemoryCtrl.CopyMemoryEx(processInformation.hProcess);
     hThread   = MemoryCtrl.CopyMemoryEx(processInformation.hThread);
 }
Exemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="startupInfo"></param>
 public STARTUPINFO(STARTUPINFO startupInfo) : this()
 {
     cb              = startupInfo.cb;
     cbReserved2     = startupInfo.cbReserved2;
     lpDesktop       = startupInfo.lpDesktop;
     lpReserved      = startupInfo.lpReserved;
     lpTitle         = startupInfo.lpTitle;
     dwFillAttribute = startupInfo.dwFillAttribute;
     dwFlags         = startupInfo.dwFlags;
     dwX             = startupInfo.dwX;
     dwXCountChars   = startupInfo.dwXCountChars;
     dwXSize         = startupInfo.dwXSize;
     dwY             = startupInfo.dwY;
     dwYCountChars   = startupInfo.dwYCountChars;
     dwYSize         = startupInfo.dwYSize;
     lpReserved2     = MemoryCtrl.CopyMemoryEx(startupInfo.lpReserved2);
     hStdError       = MemoryCtrl.CopyMemoryEx(startupInfo.hStdError);
     hStdInput       = MemoryCtrl.CopyMemoryEx(startupInfo.hStdInput);
     hStdOutput      = MemoryCtrl.CopyMemoryEx(startupInfo.hStdOutput);
 }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        public void Start(int milliSeconds = 0)
        {
            if (string.IsNullOrEmpty(AppPath))
            {
                throw new InvalidOperationException();
            }
            var cmd = $"{AppPath} {Arguments}";
            var sap = new SECURITY_ATTRIBUTES
            {
                lpSecurityDescriptor = IntPtr.Zero,
                bInheritHandle       = true
            };

            sap.nLength = Marshal.SizeOf(sap);
            var ptrsap = MemoryCtrl.CopyMemoryEx(sap);
            var sat    = new SECURITY_ATTRIBUTES
            {
                lpSecurityDescriptor = IntPtr.Zero,
                bInheritHandle       = true
            };

            sat.nLength = Marshal.SizeOf(sat);
            var ptrsat = MemoryCtrl.CopyMemoryEx(sat);

            if (!NativeMethods.CreateProcess(null, cmd, ptrsap, ptrsat, true, 0, IntPtr.Zero, null,
                                             ref StartupInfo, out ProcessInformation))
            {
                throw new Exception($"Error!\nCode: {NativeMethods.GetLastError()}");
            }

            MemoryCtrl.FreeMemoryEx(ptrsat);
            MemoryCtrl.FreeMemoryEx(ptrsap);

            if (milliSeconds > 0)
            {
                WaitForExit(milliSeconds);
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="securityAttributes"></param>
 public SECURITY_ATTRIBUTES(SECURITY_ATTRIBUTES securityAttributes) : this()
 {
     nLength              = securityAttributes.nLength;
     bInheritHandle       = securityAttributes.bInheritHandle;
     lpSecurityDescriptor = MemoryCtrl.CopyMemoryEx(securityAttributes.lpSecurityDescriptor);
 }