VB6 – Detecting whether the program is running under the control of Visual Studio or not..

Drag Article : Moved from Old Blog

Private Declare Function GetModuleHandle _
Lib "kernel32" Alias _
"GetModuleHandleA" _
(ByVal lpModuleName As String) As Long </span>
<span style="font-family: verdana; font-size: 85%">
Public Function TestEnvironment() As Boolean
Dim ModuleHandle As String
Dim EnvFileName As String
Dim EnvVal As Variant
Dim ReturnVal As Long
Dim i As Long
EnvVal = _
Array("vb.exe", _
"vb32.exe", _
"vb5.exe", _
"vb6.exe")
For i = LBound(EnvVal) To UBound(EnvVal)
ModuleHandle = EnvVal(i)
ReturnVal = GetModuleHandle(ModuleHandle)
If ReturnVal  0 Then
EnvFileName = ModuleHandle
TestEnvironment = True
Exit For
End If
Next
End Function

Private Sub Command1_Click()
If TestEnvironment() = True Then
MsgBox ("Running under IDE")
Else
MsgBox ("Running as EXE")
End If
End Sub

Another way to do is to detect whether the Visual Studio 6 IDE open or not using some API.

References Link
Question: How can I test whether a program is running at design time or run time using VB6?

3 thoughts on “VB6 – Detecting whether the program is running under the control of Visual Studio or not..

  1. An easier way than using the API is to use the divide by 0 trick (I have to admit I haven’t seen unruledboy’s solution before)

    Function InIDE() As Boolean
    On Error Resume Next
    Err.Clear
    Debug.print 1/0
    InIde = (Err.Number 0)
    Exit Function

    Sorry if the syntax is a bit dodgy, this is from memory – I’m just trying to get to grips with C# and came by to read you excellent tutorial on sending mail from Silverlight.

  2. oops, apologies I hadn’t read the full article. I see this method has already been mentioned <>

Leave a Reply

Your email address will not be published. Required fields are marked *