How to Find Out If Executable Is Running in VB Develop ShellID: Q113680
|
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.
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:
' 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)
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
Additional query words: 3.00
Keywords :
Version :
Platform :
Issue type :
Last Reviewed: June 14, 1999