title: How do I kill a process that doesn't have any windows in VB.net?
body: <p>I am new to VB.net and I am trying to write a forms app that works with Autodesk Inventor.</p>
  
  <p>Unfortunately, every time I close Inventor, the "Inventor.exe" process still stays. I didn't realize this while debugging and I only realized this when I checked the task manager after the whole system started to lag.
  Killing every process with the same name is fairly simple, but the issue is that the end user might have separate documents open in another Inventor window. So I need to write a function that only kills the Inventor processes that don't have a window open.</p>
  
  <pre><code>Public Class Form1
      Dim _invApp As Inventor.Application
      Dim _started As Boolean = False
      Public Sub New()
  
      ' This call is required by the designer.
      InitializeComponent()
  
      ' Add any initialization after the InitializeComponent() call.
      Try
          _invApp = Marshal.GetActiveObject("Inventor.Application")
  
      Catch ex As Exception
          Try
              Dim invAppType As Type = _
                GetTypeFromProgID("Inventor.Application")
  
              _invApp = CreateInstance(invAppType)
              _invApp.Visible = True
  
              'Note: if you shut down the Inventor session that was started
              'this(way) there is still an Inventor.exe running. We will use
              'this Boolean to test whether or not the Inventor App  will
              'need to be shut down.
              _started = True
  
          Catch ex2 As Exception
              MsgBox(ex2.ToString())
              MsgBox("Unable to get or start Inventor")
          End Try
      End Try
  
  End Sub
  </code></pre>
  
  <p>Another section where I start a process, which is a specific 3D model file.</p>
  
  <pre><code>Public Sub SaveAs(oTemplate As String)
      'define the active document
      Dim oPartDoc As PartDocument = _invApp.ActiveDocument
      'create a file dialog box
      Dim oFileDlg As Inventor.FileDialog = Nothing
      Dim oInitialPath As String = System.IO.Path.GetFullPath("TemplatesResources\" &amp; oTemplate)
      _invApp.CreateFileDialog(oFileDlg)
  
      'check file type and set dialog filter
      If oPartDoc.DocumentType = kPartDocumentObject Then
          oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"
      ElseIf oPartDoc.DocumentType = kAssemblyDocumentObject Then
          oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
      ElseIf oPartDoc.DocumentType = kDrawingDocumentObject Then
          oFileDlg.Filter = "Autodesk Inventor Drawing Files (*.idw)|*.idw"
      End If
  
      If oPartDoc.DocumentType = kAssemblyDocumentObject Then
          oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
      End If
  
      'set the directory to open the dialog at
      oFileDlg.InitialDirectory = "C:\Vault WorkSpace\Draft"
      'set the file name string to use in the input box
      oFileDlg.FileName = "######-AAAA-AAA-@@"
  
      'work with an error created by the user backing out of the save
      oFileDlg.CancelError = True
      On Error Resume Next
      'specify the file dialog as a save dialog (rather than a open dialog)
      oFileDlg.ShowSave()
  
      'catch an empty string in the imput
      If Err.Number &lt;&gt; 0 Then
          MessageBox.Show("Any changes made from here will affect the original template file!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification)
      ElseIf oFileDlg.FileName &lt;&gt; "" Then
          Dim MyFile As String = oFileDlg.FileName
          'save the file
          oPartDoc.SaveAs(MyFile, False)
          'open the drawing document
          System.Diagnostics.Process.Start(oInitialPath &amp; ".idw")
          Dim oFinalPath As String = oPartDoc.FullFileName
          MessageBox.Show(oFinalPath, "", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification)
          MessageBox.Show("Loaded", "", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification)
          Dim oDrawingDoc As DrawingDocument = _invApp.Documents.ItemByName(oInitialPath &amp; ".idw")
          'oDrawingDoc.SaveAs()
  
      End If
  End Sub
  </code></pre>
  
  <p>Any help is appreciated.
  Thanks</p>