is there any way to know (Within the source code) if a project is running from visual basic, or from it's compiled EXE ?
Printable View
is there any way to know (Within the source code) if a project is running from visual basic, or from it's compiled EXE ?
first of all in runtime app.EXEname returns the projectname. So if the you make it do:
If app.EXEname = "Project1" then
'Code here for if it is in VB
End If
now this poses a problem if your project name is the same as what your compiling it as, but there is an easy solution and that is to rename your project something odd like "prjProgramThingThatIsThis1". (you get the idea)
Also, something I've used before, but I'm not sure if it works this way on all computers of if mine is just a freak. it seems to me that for some reason when compiled app.EXEname returns in all caps and it returns in the case you type it in in run-time. So, you could do this:
if app.EXEname=ucase(app.EXEname) then
'code here for if it's running as an EXE
end if
:D Hope this helps,
Try this:
Code:Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Public Function Autonome() As Boolean
Dim strFileName As String
Dim lngCount As Long
strFileName = String(255, 0)
lngCount = GetModuleFileName(App.hInstance, strFileName, 255)
strFileName = Left(strFileName, lngCount)
Dim p
p = UCase(Right(strFileName, 7))
'Attention here
If p <> "VB6.EXE" Then
'code autonome
ideorexe = True
Else
'function under VB6
ideorexe = False
End If
End Function
Or, if the classname is ThunderForm, then you are running it through VB, whereas if the classname is ThunderRT5Form (or ThunderRT6Form) then you are running it from an EXE.
Code:Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Sub Command1_Click()
Dim sClass As String
Dim iLength As Integer
sClass = Space(255)
iLength = GetClassName(hwnd, sClass, 255)
sClass = Trim(sClass)
sClass = Left(sClass, Len(sClass) - 1)
'Change to ThunderRT6Form if you have VB6
If sClass = "ThunderRT5Form" Then MsgBox "It's running from exe"
If sClass = "ThunderForm" Then MsgBox "It's running from vb"
End Sub
Thanks all for help :)
Good Code Megatron.
don't forget about vb4! (vb32.exe)
Making Matthew's code universal:
end ifCode:if len(strFileName) > 6 then p = UCase(Right(strFileName, 7))
if p = "VB5.EXE" or p = "VB6.EXE" or p = "VB32.EXE" _
or p = "VBNET.EXE" then
'guard against future versions: replace the above line
'with if left$(p,2) = "VB" then
ideorexe = true
else
ideorexe = false
Declare a boolean variable like
Public RunningInIDE as Boolean
Create a Function Like
Function CheckIDE() as boolean
RunningInIDE=TRUE
CheckIDE=TRUE
End Function
Then in your startup
Sub Main()
Debug.Assert ChecKIDE 'This will not be called if is a exe
End Sub
_@" Hope this helps "@_