Determine if a particular exe file is running


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Determine if a particular exe file is running

  1. #1
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263

    Determine if a particular exe file is running

    I have a program that only runs from an external drive. I am creating an Update program that downloads the latest version and updates the program.

    Is there a way to tell if the file I am trying to update is currently running?

    I can't assume that if the program is running that it is the one I am trying to update; because they could be running it from one drive while updating the program on another drive.

    If the program file I am trying to update is running, then I want to give them a warning message with the option to either cancel the update or shut down the program before updating it.

    Thanks!

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    If it is running it should show up in task manager and you should be able to find it there using WMI.

    Here is an example: http://www.freevbcode.com/ShowCode.asp?ID=7313
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    Thanks That worked great! Here is the Test Code I Used:
    Code:
    Imports System.Management
    
    Public Class frmMain
    
      Const WM_QUIT As UInteger = &H12
      Private Declare Function PostThreadMessage Lib "user32.dll" Alias "PostThreadMessageA" (ByVal idThread As Integer, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean
    
      Private Sub EndProg()
        ' This version uses WMI which also gives access to the Exe file's Path
        Dim ThreadID As Integer = 0
        'See if MyProgram is running from External drive 'G', and shut it down gracefully
        Dim Win32Procs As New ManagementObjectSearcher("SELECT * FROM Win32_Process Where (ExecutablePath = 'G:\MyProgram.exe')")
        For Each Win32Proc As ManagementObject In Win32Procs.Get()
          'Debug.Print("Name:" & Win32Proc("Name") & "  Path:" & Win32Proc("ExecutablePath")) 'Items.Add(disk("Name").ToString())
          Dim Win32Threads As New ManagementObjectSearcher("SELECT * FROM Win32_Thread Where (ProcessHandle = '" & Win32Proc("ProcessId").ToString & "')")
          For Each Win32Thread As ManagementObject In Win32Threads.Get()
            ThreadID = CInt(Win32Thread("Handle"))
            PostThreadMessage(ThreadID, WM_QUIT, IntPtr.Zero, IntPtr.Zero)
          Next
        Next
      End Sub
    
      Private Sub btEndIt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btEndIt.Click
        EndProg()
      End Sub
    End Class
    Notice here that you could shutdown all occurances of MyProgram.exe by changing the 'Where' Clause to look for Name = 'MyProgram.exe' instead of looking for ExecutablePath = 'G:\MyProgram.exe'

Similar Threads

  1. Create Setup file in VB for flash exe file
    By mrsupra in forum VB Classic
    Replies: 0
    Last Post: 10-19-2005, 10:32 AM
  2. How to determine if an exe file exist
    By Hian Chew in forum VB Classic
    Replies: 0
    Last Post: 08-06-2001, 11:05 PM
  3. Execute the EXE file from Start-Run
    By Sinni in forum VB Classic
    Replies: 7
    Last Post: 07-25-2001, 02:07 PM
  4. Replies: 0
    Last Post: 06-27-2001, 04:11 PM
  5. Conversion of class file to exe file
    By arunprasad ks in forum Java
    Replies: 10
    Last Post: 09-19-2000, 07:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center