Skip Navigation Links.
How to Tell if you are Running in the IDE
Language(s):Visual Basic 6.0
Category(s):IDE

Using the App object and the GetModuleFileName API to determine if you are running in the IDE.

' How to Tell if you are Running in the IDE

' Using the App object and the GetModuleFileName API 
' to determine if you are running in the IDE. 
'
' Jon Vote 

' 02/2002 
'
' 1) Create a new project. Form1 will be created by default.
' 2) Add a Command Button to the Form. 
' 3) Paste the following code into the declarations section of Form1:

' --- Begin code for Form1

'How to tell if your program is running in the IDE
'
'Jon Vote, Idioma Software Inc.
'
'02/2002
'
'www.idioma-software.com

Option Explicit

Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long

Private Sub Command1_Click()
  
  MsgBox "Running in IDE? " & RunninInIDE

End Sub

Private Sub Form_Load()

  Me.Caption = "How to tell if running in the IDE"
  
  Command1.Caption = "&Test"
  
End Sub

'RunningInIDE - Returns TRUE if running in IDE, else FALSE
Private Function RunninInIDE() As Boolean

  'This routine compares the path name returned by GetModuleFileName
  'with App.Path & App.ExeName. If they are the same, the .exe is running.
  'If not, you are running in the IDE.
   
  Dim strModulePath As String
  Dim strAppPath As String
  Dim lngCount As Long
  
  strModulePath = String(1000, 0)
  lngCount = GetModuleFileName(App.hInstance, strModulePath, 1000)
  strModulePath = Left(strModulePath, lngCount)
    
  strAppPath = App.Path & "\" & App.EXEName & ".exe"
  Debug.Print "Module Path: " & strModulePath
  Debug.Print "App Path: " & strAppPath
  
  If StrComp(strModulePath, strAppPath, vbTextCompare) = 0 Then
    RunninInIDE = False
  Else
    RunninInIDE = True
  End If
  
End Function


' --- End code for Form1 ---

This article has been viewed 4935 times.
The examples on this page are presented "as is". They may be used in code as long as credit is given to the original author. Contents of this page may not be reproduced or published in any other manner what so ever without written permission from Idioma Software Inc.