ac# コードからプロセスとしてブラウザー インスタンスを開始しようとしています。次に、ブラウザの同じインスタンスを強制終了したいと思います。プロセス id で同じインスタンスを見つけようとしました。しかし、プロセスIDは、タスクマネージャーと、プロセスを開始したときに取得した初期IDで異なります。解決策は何ですか?なぜこうなった?開発環境はwindows7です。
int ID= 0;
void Start()
{
ProcessStartInfo startInfo = new ProcessStartInfo("iexplore.exe");
startInfo.Arguments = "http://www.google.com";
Process ieProcess = Process.Start(startInfo);
ID= ieProcess.Id;
}
void Stop()
{
foreach (Process p in System.Diagnostics.Process.GetProcessesByName("iexplore"))
{
if ((p.Id == ID))
{
p.Kill();
}
}