By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,558 Members | 1,607 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

Check whether project is running VB IDE

AHMEDYO
100+
P: 112
Hi every one...

This code simply show if your project running from VB6 IDE or running as single exe file, because visual basic 6.0 run your project within VB6.exe process and it doesn't create new exe file for you like VB.NET, this situation make some problems as when you try to use resource with API call, all your functions will get failed.

Program: Check whether project is running VB IDE
Language: VB

(1) Build new project, add a form
(2) Add a command button, namely Command1
(3) Insert the entire code elsewhere
(4) Insert MsgBox IfUsingVB6IDE under Command1

TIP: If Message box reports True, you are indeed running VB IDE

Heads up: The remaining code should be added at the very top of your code pane, or else you may get an error stating code cannot be added after Sub.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Private Declare Function GetModuleBaseNameA Lib "Psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
  4. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
  5.  
  6. Private Const PROCESS_NAME_MAX_BYTES As Long = 255 
  7.  
  8. Private Property Get IfUsingVB6IDE() As Boolean
  9. Dim ProcessHandle As Long
  10. Dim ProcessName As String
  11. Dim ProcessNameLen As Long
  12. Dim NameBuffer As String * PROCESS_NAME_MAX_BYTES
  13. ProcessHandle = GetCurrentProcess() 'Get Current Process pseudo handle
  14. ProcessNameLen = GetModuleBaseNameA(ProcessHandle, App.hInstance, NameBuffer, PROCESS_NAME_MAX_BYTES) 'Get current Process Base module name (file name)
  15. ProcessName = Left$(NameBuffer, ProcessNameLen) 'clear remaining unused buffer bytes and get only file name
  16. If (UCase$(ProcessName) = "VB6.EXE") Then IfUsingVB6IDE = True 'if current process VB6.exe then we are in VB6 IDE, if else we running as separated process
  17. End Property
  18.  
  19. Private Sub Command1_Click()
  20. MsgBox IfUsingVB6IDE
  21. End Sub
  22.  
  23.  
Kudos to OP for posting this...
Nov 21 '07 #1
Share this Article
Share on Google+
1 Comment


P: 3
Expand|Select|Wrap|Line Numbers
  1. 'one more simple way
  2. Public Enum EVbRunMode
  3.     RunMode_Compiled = True
  4.     RunMode_FromIDE = False
  5. End Enum
  6. Public Function AppRunMode() As EVbRunMode
  7.     On Error Resume Next
  8.     Debug.Print 1 / 0
  9.     AppRunMode = Err.Number = 0
  10. End Function
Sep 17 '15 #2