HOWTO: Tell Whether an App Runs in VB Design EnvironmentID: Q118819
|
This article describes how a Visual Basic application can determine whether it is running in the design environment or as an executable file. Two ways that Visual Basic does this are explained.
Visual Basic provides the APP object, which has the property EXENAME.
APP.EXENAME reports the name of the executable file when it runs as an
executable file. However, in the design environment, APP.EXENAME reports
the name of the project. If you use different names for the project and the
executable file, then you can use APP.EXENAME to determine whether an
application is running in the Visual Basic design environment or as an
executable file.
You can also use the Windows API to determine whether an application is
running in the Visual Basic Design Environment or as an executable file.
When running in the design environment, the application's module name is
"VB." However, as an executable file the module name matches the executable
file name that is chosen when compiling the application to an executable
file from Visual Basic.
Type TASKENTRY
dwSize As Long
hTask As Integer
hTaskParent As Integer
hInst As Integer
hModule As Integer
wSS As Integer
wSP As Integer
wStackTop As Integer
wStackMinimum As Integer
wStackBottom As Integer
wcEvents As Integer
hQueue As Integer
szModule As String * 10
wPSPOffset As Integer
hNext As Integer
End Type
' The following declare must be entered on a single line
Declare Function TaskFindHandle Lib "Toolhelp" (lpte As TASKENTRY,
ByVal hTask As Integer) As Integer
Declare Function GetCurrentTask Lib "Kernel" () As Integer
Function VBDesignEnvironment () As Integer
Dim TE As TASKENTRY
Dim ModuleName As String
Dim hTask As Integer
Dim r
hTask = GetCurrentTask()
TE.dwSize = Len(TE)
r = TaskFindHandle(TE, hTask)
ModuleName = Left(TE.szModule, InStr(TE.szModule, Chr(0)) - 1)
If ModuleName = "VB" Then
VBDesignEnvironment = True
Else
VBDesignEnvironment = False
End If
End Function
Sub Form_Load ()
Me.Show
If VBDesignEnvironment() Then
Print "Design Environment"
Else
Print "Executable"
End If
End Sub
Additional query words: 3.00 .EXE VB.EXE debug run-time IDE
Keywords : kbcode EnvtRun
Version : 3.00
Platform : WINDOWS
Issue type :
Last Reviewed: June 14, 1999