title: c# close ie tab based on knowing process ID
body: <p>so adding improvements to existing code. Right now its opening up IE windows to nav to certain sites</p>
  
  <pre><code>            startInfo.CreateNoWindow = false;
          startInfo.UseShellExecute = false;
          startInfo.FileName = Configuration.IExplorerLocation();
          startInfo.WindowStyle = ProcessWindowStyle.Hidden;
          startInfo.Arguments = url;
  
          // Start the process with the info we specified.
  
          Process exeProcess = Process.Start(startInfo);
  </code></pre>
  
  <p>so now the client wants us to close that window if they attempt to click on that same nav button in the UI. So I need to hold something, to go an close that later if they attempt again. I have saved off the handle, the process id etc to attempt to close later but it seems to then have no clue that window exists. I think part of my issue might be that IE kinda has a main PID and any new windows get new PID's but I save off the PID I jsut created and 50ms later it doesnt know it exists to close it.. using this code</p>
  
  <pre><code>                    log.Info(fn + "parse -" + _iNypIEProcessIdName);
                  string[] ProcData = _iNypIEProcessIdName.Split('-');
                  int ProcId = 0;
                  log.Info(fn + " "+ ProcData[0]);
                  Int32.TryParse(ProcData[0], out ProcId);
                  //Process exeProcess as new Process;
                  Process CheckProcess = null;
                  log.Info(fn + "2");
                  try
                  {
                      CheckProcess = Process.GetProcessById(ProcId);
                  }
                  catch (Exception e)
                  {
                      log.Error(fn + " iNYP process not found to remove ", e);
                  }
                  if (CheckProcess.ProcessName == ProcData[1])
                  {
                      // then I think we have a match ??
                      log.Debug(fn + " Attempting to close ID" + ProcId + " " + ProcData[1]);
                      CheckProcess.Close();
                  }
  </code></pre>
  
  <p>so not sure if just my code is wrong...  but I guess I'm more looking for a good way to open a process... get some info on it that I can later use to close it if they attempt to NAV to pretty much the same URL. Should I just loop through all existing IE windows and find the same URL and close ? I just figured trying to get the handle or the PID would be cleaner.. and side note when I try to get the handle after the process starts the window is not fully up and the handle is ZERO.. so any advice is welcome !!!</p>