Microsoft KB Archive/113680

= How to Find Out If Executable Is Running in VB Develop Shell =

Article ID: 113680

Article Last Modified on 1/9/2003

-

APPLIES TO


 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q113680



SUMMARY
If a Visual Basic application needs to know if it is running in the Visual Basic development shell, the application can call the Windows API ModuleFileName function to find out what its module name is. If the ModuleFileName function returns VB.EXE, it is running in the Visual Basic development shell.



MORE INFORMATION
The following example shows how to find out if a program is running interpreted within the Visual Basic development shell as opposed to running as a compiled executable:

Step-by-Step Example
 Start a new project in Visual Basic. Form1 is created by default.  Add the following code to the general declarations section of Form1: ' Enter each of the following Declare statements as one, single line: Declare Function GetModuleFileName Lib "Kernel" (ByVal hModule As Integer, ByVal lpFilename As String,     ByVal nSize As Integer) As Integer Declare Function GetWindowWord Lib "User" (ByVal hWnd As Integer,     ByVal nIndex As Integer) As Integer

Const GWW_HINSTANCE = (-6)

  Add the following code to the Form_Load event of Form1: Sub Form_Load Dim ModuleName As String Dim FileName As String Dim hInst, ret As Integer ModuleName = String$(128, Chr$(0)) ' Get the hInstance application: hInst = GetWindowWord(Me.hWnd, GWW_HINSTANCE) ' Get the ModuleFileName: ' Enter the following two lines as one, single line: ModuleName = Left$(ModuleName,        GetModuleFileName(hInst, ModuleName, Len(ModuleName))) If (Len(ModuleName)) > 0 Then ' Get the "." in the file name. Then go back three characters. ' FileName should = \VB.EXE, so check for the backslash (\) ' because FileName could be GVB.EXE, which isn't the ' VB executable name: FileName = Mid$(ModuleName, InStr(ModuleName, ".") - 3) If FileName = "\VB.EXE" Then MsgBox "In VB development Shell" Else MsgBox "Not in VB development Shell" End If     End If   End Sub

 Run the program.

If you are running within the Visual Basic environment, you will get the "In VB development Shell" message box. If you are running a compiled executable, you will get the "Not in VB development Shell" message.

Additional query words: 3.00

Keywords: KB113680

-

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

© Microsoft Corporation. All rights reserved.