Solved

Running inside VB5 or in EXE?

Posted on 1998-06-25
7
271 Views
Last Modified: 2010-05-03
I want to know if my program is running inside the VB5 development environment or in compiled EXE.
I can not use the App.EXEName because it will return the same name if the application name and the EXE name is the same.
Also, I succeeded to detect this in VB4 using API GetModuleFileName and GetWindowWord, but in VB5 they always report that the project is running in EXE. I think this is probably because VB5 compiles and runs the project as a true compiled application which is not the case in VB4 (I think).
I also tried to check the 'Compile to p-code' in the compile options, but got the same results.
Thanks.
0
Comment
Question by:gelco
7 Comments
 

Author Comment

by:gelco
ID: 1464344
Adjusted points to 200
0
 
LVL 2

Expert Comment

by:marti
ID: 1464345
One possible solution could be to set command line arguments to something specific while working in VB5 development environment.
0
 

Author Comment

by:gelco
ID: 1464346
Thanks marti, but I think this will not solve my problem.
I want some API code or some other way to do the real job.
Thanks again.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Accepted Solution

by:
yowkee earned 200 total points
ID: 1464347
gelco,

  Let's try this:

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

Function IsRunUnderVB5() As Boolean
 Dim S As String, Length
 Length = 256
 S = String(Length, 0)
 Call GetModuleFileName(0, S, Length)
 S = Left(S, InStr(S, Chr(0)) - 1)
 IsRunUnderVB5 = UCase(Right(S, 7)) = "VB5.EXE"
End Function
Private Sub Form_Load()
    If IsRunUnderVB5 Then
        MsgBox "Run Under VB5"
    Else
        MsgBox "Run in Exe"
    End If
End Sub
----------

Regards.
0
 

Expert Comment

by:LMSuporte
ID: 1464348
I am making this an answer: These function  doesnt require any API at all. It will return true if you are running in design time, false otherwise. To make sure this will work, go to the menu TOOLS, then OPTIONS, then choose the tab GENERAL and make sure your "Error Trapping" is set to "BREAK IN CLASS MODULE" (under VB5). In all other versions of VB, it will work just fine.
(PS: This might not work properly if you are creating an OCX and a VBP in the same project)

Public Function IsDesign() As Boolean

    On Error GoTo IsDesignIsTrue

    Debug.Print 1 / 0
    IsDesign = False
    Exit Function

IsDesignIsTrue:
    IsDesign = True

End Function

0
 
LVL 9

Expert Comment

by:Dalin
ID: 1464349
yowkee,
congradulations on your making the top 15. Keep up the good work.
regards
Dalin
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1464350
Thanks, Dalin. It seem I start to be lazy after being the 15th :P...... Hope I could come back after good rest. My respect to you as you keep answering question here. It's not easy, really. :)

And gelco, are you there? Come and evaluate mine and LMSuporte's post.

 
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now