Jul 6, 2011

example for Process. WaitForInputIdle and WaitForExit

Causes the Process component to wait indefinitely for the associated process to enter an idle state. This overload applies only to processes with a user interface and, therefore, a message loop.


using System.Runtime.InteropServices;


 [DllImport("user32.dll")]
        static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        [DllImportAttribute("User32.dll")]
        private static extern IntPtr FindWindow(String ClassName, String WindowName);






 public void GetMSInfo()
       {


            try
            {


                string strArguments = " /report" + space.ToString() + path + "\\MS32INFO.txt";
                System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
                psi.WindowStyle = ProcessWindowStyle.Hidden;
                psi.UseShellExecute = false;
                psi.RedirectStandardOutput = true;
                psi.CreateNoWindow = true;
                psi.FileName = "msinfo32.exe";
                psi.Arguments = strArguments;
                
                System.Diagnostics.Process si = new System.Diagnostics.Process();
                si.StartInfo = psi;
                IntPtr hWnd;
                si.Start();
               
               si.WaitForInputIdle();
                hWnd = FindWindow(null, "System Information");
                ShowWindow(hWnd, 0);
                
                si.WaitForExit();
                
              //  string output = si.StandardOutput.ReadToEnd();
                si.Close();
            }


            catch (Exception ex)
            {
                throw ex;
            }


        }

No comments:

Post a Comment