How to kill (or) close a process

Mar 12 2009 7:53 AM

 Hi, my prog is bellow,im using process.close() and process.kill()

but nmy process is not terminated,after executing the program onetime if change the code in prog it is giving compilation error like this:

unable to copy the file into process.exe becuse it is being used by another processs, then iam restarting the system after taht it is working ,plss tell me the sol

System.Diagnostics.Process myProcess = new System.Diagnostics.Process();

myProcess.StartInfo.FileName = "D:\\Program Files\\InterVideo\\WinDVR\\WinDvr.exe";

myProcess.StartInfo.UseShellExecute = false;

myProcess.Start();

myProcess.WaitForInputIdle(2000);

IntPtr hWnd = myProcess.MainWindowHandle;

//Console.WriteLine(hWnd);

MessageBox.Show(hWnd.ToString());

SetForegroundWindow(hWnd);

bool p = SetForegroundWindow(hWnd);

if (!p)

MessageBox.Show("Could not set focus");

myProcess.CloseMainWindow();

myProcess.Close();

myProcess.Kill();

SendKeys.SendWait("r");

}

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]

public static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]

public static extern IntPtr SetFocus(IntPtr hWnd);


Answers (1)