Microsoft KB Archive/84836

= How to Determine the Number of VB Applications Running at Once =

Article ID: 84836

Article Last Modified on 12/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 1.0 Standard Edition

-



This article was previously published under Q84836



SUMMARY
To determine the total number of Microsoft Visual Basic for Windows applications running at any given time, you can use the Microsoft Windows API functions GetModuleHandle and GetModuleUsage.



MORE INFORMATION
The following code fragment demonstrates a technique to find the total number of Visual Basic for Windows applications currently executing by determining the number of instances of the Visual Basic run-time module (VBRUN100.DLL) with the Windows API functions GetModuleHandle and GetModuleUsage. Remember that Visual Basic for Windows itself is not counted; only applications created with Visual Basic for Windows are included.

Steps to Create Example Program
 Start several Visual Basic for Windows applications and leave them running. Run Visual Basic for Windows, or from the File menu, choose New Project (press ALT, F, N) if Visual Basic for Windows is already running. Form1 is created by default.  Enter the following Windows API function declarations into the General Declarations section of Form1: Declare Function GetModuleUsage% Lib &quot;kernel&quot; (ByVal hModule%) Declare Function GetModuleHandle% Lib &quot;kernel&quot; (ByVal FileName$)

  Place a command button (Command1) on Form1. Double-click that button to open the Code window. In the Command1_Click procedure, add the following code: Sub Command1_Click msg$ = &quot;Number of executing VB Apps: &quot;

hModule% = GetModuleHandle(&quot;VBRUN300.DLL&quot;) ' For Visual Basic versions 1.0 and 2.0 for Windows, use ' VBRun100.DLL and VBRun2.00.DLL respectively. nInstances% = GetModuleUsage(hModule%)

msg$ = msg$ + Str$(nInstances%) MsgBox msg$ End Sub

 From the File menu, choose Make EXE File. Press the F5 key to run the file. Click the command button.</li></ol>

A message box displays the total number of executing Visual Basic for Windows applications.

NOTE: This program itself will count as one application.

Additional query words: 2.00 3.00

Keywords: KB84836

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.