Results 1 to 7 of 7

Thread: my project is running from VB or EXE ?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 1999
    Location
    Bahrain
    Posts
    41
    is there any way to know (Within the source code) if a project is running from visual basic, or from it's compiled EXE ?

  2. #2
    Lively Member Bios's Avatar
    Join Date
    Nov 1999
    Location
    Richton Park, IL, USA
    Posts
    71
    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


    Hope this helps,
    Bios
    Age: 17
    Languages: (Q)BASIC, Visual Basic, Dark Basic,C/C++, Visual C++, Perl, Java Script, HTML, ASP

    "DO:BEEP:LOOP"

  3. #3
    Guest
    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

  4. #4
    Guest
    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

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 1999
    Location
    Bahrain
    Posts
    41

    Wink

    Thanks all for help

  6. #6
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    Good Code Megatron.
    don't forget about vb4! (vb32.exe)
    Making Matthew's code universal:
    Code:
    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
    end if
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  7. #7
    New Member
    Join Date
    Feb 2001
    Location
    UK
    Posts
    2

    Wink

    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 "@_

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width