Visual Basic FAQ

GetModuleHandle: Determine if a Specific App is Already Running (16-bit)
     
Posted:   Thursday December 26, 1996
Updated:   Monday December 26, 2011
     
Applies to:   VB3, VB4-16 on Windows 3.x
    
Related:   CreateToolhelp32Snapshot: List Running Processes
EnumWindows: Enumerate Windows via a Callback
     
 Prerequisites
None.

This is a 16-bit FAQ to determine if another specific application is running. The Windows 3x GetModuleUsage API is not implemented under the Win32 operating system.  For 32-bit Windows versions, use CreateToolhelp32Snapshot or EnumWindows.
 BAS Module Code
None.

 Form Code
Add a command button to a form along with the following code:

Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Declare Function GetModuleUsage Lib "kernel" _
   (ByVal hModule As Integer) As Integer

Private Declare Function GetModuleHandle Lib "kernel" _
   (ByVal ApplicationFileName As String) As Integer


Sub Command1_Click()

  If GetModuleUsage(GetModuleHandle("notepad.exe")) Then

     MsgBox "Windows Notepad is already running!", 56
     Unload Me

  End If

End Sub
 Comments
Run the app, and click the command button. If Notepad is running, the message box will appear.

 
 

PayPal Link
Make payments with PayPal - it's fast, free and secure!

 
 
 
 

Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy

 

Hit Counter