IDE or EXE? now that's the question 
Author Message
 IDE or EXE? now that's the question

I try to find a reliable way to distinguish the app instances between VB IDE
and compiled EXE.

Based on the fact that debug.print will not be executed in a compiled EXE, I
do the following:

In a form, add command1:

Option Explicit

Private bCompiledEXE As Boolean

Private Sub IsCompiledEXE()
    bCompiledEXE = True
    Debug.Print IsCompiledEXECallback
End Sub

Private Function IsCompiledEXECallback() As String
    bCompiledEXE = False
End Function

Private Sub Command1_Click()
If bCompiledEXE Then
    MsgBox "This is compiled EXE"
Else
    MsgBox "This is VB IDE"
End If
End Sub

Private Sub Form_Load()
    IsCompiledEXE
End Sub

However I get "This is VB IDE" even when I run the compiled EXE.

Anyone knows a way to do this?

TIA.
Aristotelis



Thu, 14 Oct 2004 19:08:13 GMT  
 IDE or EXE? now that's the question
From MSDN:
There are two methods you can use to determine if your program is running
from the IDE or the EXE.

Method 1: EXE File Name Differs from Project Name
The App object contains general information about the program, such as the
executable file name. If the project name and the compiled version of the
project have different file names, then you can use the App.EXEName property
to determine if the EXE is running or if your project is running in the IDE.
If the program is running from the Visual Basic IDE, the EXEName property
returns the project name. When a program is running from an executable, the
EXEName property contains the EXE file name.

Method 2: EXE File Name and the Project Name Are the Same
If the project name and the compiled version share the same name, then use
the GetModuleFileName API function to determine if your program is running
from the IDE or from a compiled version. GetModuleFileName retrieves the
full path and filename for the executable file containing the specified
module. If the function returns a path to the Visual Basic file, VB5.EXE,
then the program is running in the IDE. Otherwise, the program is running
from an executable file.

GetModuleFileName requires the following arguments:

  a.. hModule: the handle to the module whose filename you want. Use the
hInstance property of the APP object for this parameter.

  b.. lpFilename: a pointer to buffer to receive module path. Create a
string variable 255 characters long and pass that variable for this
parameter.

  c.. nSize: the size of buffering characters. Use 255 for this parameter.

The next section illustrates how to create a sample project that implements
both of these methods.

Sample Project
  1.. Start a new Standard EXE project in Visual Basic. Form1 is created by
default.

  2.. Add two CommandButtons to Form1.

  3.. Copy the following code to the Code window of Form1:

      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 Form_Load()
         'Set the command button names
         Command1.Caption = "Different Project and Executable Names"
         Command2.Caption = "Similar File Names"
      End Sub

      Private Sub Command1_Click()
          'Click this button if the project name and the compiled file
          'name are different.
          MsgBox VB.App.EXEName
      End Sub

      Private Sub Command2_Click()
         'Click this button if the project name and the compiled file
         'name are the same.

         Dim strFileName As String
         Dim lngCount As Long

         strFileName = String(255, 0)
         lngCount = GetModuleFileName(App.hInstance, strFileName, 255)
         strFileName = Left(strFileName, lngCount)

         If UCase(Right(strFileName, 7)) <> "VB5.EXE" Then
             MsgBox "Compiled Version"
         Else
             MsgBox "IDE Version"
         End If
      End Sub

  4.. Save the project with the IDEApp project name.

  5.. Compile two different executable files from this project. Use the
default file name, IDEApp.exe, for the first executable file. For the second
executable file, use the file name EXEApp. To compile the project, complete
the following steps:

    a.. From the File menu, click Make IDEApp.exe. The Make Project dialog
box appears.

    b.. Use the default file name or type your file name in the File name
text box.

    c.. Click OK to create the executable file and to close the Make project
Dialog box.

  6.. On the Run menu, click Start or press the F5 key to start the program.
Click the Different Project and Executable Names button. A message box
displays with the message, "IDEApp," to indicate that the program is running
from the IDE. Click the Similar File Names button. A message box displays
with the message, "IDE Version," to indicate the program is running from the
IDE. Close down the project.

  7.. Run either executable file and click the CommandButtons. A message box
is shown indicating the program is running from an executable file.

REFERENCES
For information about determining if a 16-bit Visual Basic application is
running in the design environment, please see the following article in the
Microsoft Knowledge Base:

  Q118819 : HOWTO: Tell Whether an App Runs in VB Design Environment



Quote:
> I try to find a reliable way to distinguish the app instances between VB
IDE
> and compiled EXE.

> Based on the fact that debug.print will not be executed in a compiled EXE,
I
> do the following:

> In a form, add command1:

> Option Explicit

> Private bCompiledEXE As Boolean

> Private Sub IsCompiledEXE()
>     bCompiledEXE = True
>     Debug.Print IsCompiledEXECallback
> End Sub

> Private Function IsCompiledEXECallback() As String
>     bCompiledEXE = False
> End Function

> Private Sub Command1_Click()
> If bCompiledEXE Then
>     MsgBox "This is compiled EXE"
> Else
>     MsgBox "This is VB IDE"
> End If
> End Sub

> Private Sub Form_Load()
>     IsCompiledEXE
> End Sub

> However I get "This is VB IDE" even when I run the compiled EXE.

> Anyone knows a way to do this?

> TIA.
> Aristotelis



Mon, 18 Oct 2004 23:40:28 GMT  
 IDE or EXE? now that's the question
Method 3)

On Error Resume Next
Debug.Print 1/0
If Err Then MsgBox "IDE Mode !"

Method nicked from Rick Rothstein

On Thu, 02 May 2002 15:40:28 GMT, "Ivan Demkovitch"

Quote:

>From MSDN:
>There are two methods you can use to determine if your program is running
>from the IDE or the EXE.

>Method 1: EXE File Name Differs from Project Name
>The App object contains general information about the program, such as the
>executable file name. If the project name and the compiled version of the
>project have different file names, then you can use the App.EXEName property
>to determine if the EXE is running or if your project is running in the IDE.
>If the program is running from the Visual Basic IDE, the EXEName property
>returns the project name. When a program is running from an executable, the
>EXEName property contains the EXE file name.

>Method 2: EXE File Name and the Project Name Are the Same
>If the project name and the compiled version share the same name, then use
>the GetModuleFileName API function to determine if your program is running
>from the IDE or from a compiled version. GetModuleFileName retrieves the
>full path and filename for the executable file containing the specified
>module. If the function returns a path to the Visual Basic file, VB5.EXE,
>then the program is running in the IDE. Otherwise, the program is running
>from an executable file.

>GetModuleFileName requires the following arguments:

>  a.. hModule: the handle to the module whose filename you want. Use the
>hInstance property of the APP object for this parameter.

>  b.. lpFilename: a pointer to buffer to receive module path. Create a
>string variable 255 characters long and pass that variable for this
>parameter.

>  c.. nSize: the size of buffering characters. Use 255 for this parameter.

>The next section illustrates how to create a sample project that implements
>both of these methods.

>Sample Project
>  1.. Start a new Standard EXE project in Visual Basic. Form1 is created by
>default.

>  2.. Add two CommandButtons to Form1.

>  3.. Copy the following code to the Code window of Form1:

>      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 Form_Load()
>         'Set the command button names
>         Command1.Caption = "Different Project and Executable Names"
>         Command2.Caption = "Similar File Names"
>      End Sub

>      Private Sub Command1_Click()
>          'Click this button if the project name and the compiled file
>          'name are different.
>          MsgBox VB.App.EXEName
>      End Sub

>      Private Sub Command2_Click()
>         'Click this button if the project name and the compiled file
>         'name are the same.

>         Dim strFileName As String
>         Dim lngCount As Long

>         strFileName = String(255, 0)
>         lngCount = GetModuleFileName(App.hInstance, strFileName, 255)
>         strFileName = Left(strFileName, lngCount)

>         If UCase(Right(strFileName, 7)) <> "VB5.EXE" Then
>             MsgBox "Compiled Version"
>         Else
>             MsgBox "IDE Version"
>         End If
>      End Sub

>  4.. Save the project with the IDEApp project name.

>  5.. Compile two different executable files from this project. Use the
>default file name, IDEApp.exe, for the first executable file. For the second
>executable file, use the file name EXEApp. To compile the project, complete
>the following steps:

>    a.. From the File menu, click Make IDEApp.exe. The Make Project dialog
>box appears.

>    b.. Use the default file name or type your file name in the File name
>text box.

>    c.. Click OK to create the executable file and to close the Make project
>Dialog box.

>  6.. On the Run menu, click Start or press the F5 key to start the program.
>Click the Different Project and Executable Names button. A message box
>displays with the message, "IDEApp," to indicate that the program is running
>from the IDE. Click the Similar File Names button. A message box displays
>with the message, "IDE Version," to indicate the program is running from the
>IDE. Close down the project.

>  7.. Run either executable file and click the CommandButtons. A message box
>is shown indicating the program is running from an executable file.

>REFERENCES
>For information about determining if a 16-bit Visual Basic application is
>running in the design environment, please see the following article in the
>Microsoft Knowledge Base:

>  Q118819 : HOWTO: Tell Whether an App Runs in VB Design Environment



>> I try to find a reliable way to distinguish the app instances between VB
>IDE
>> and compiled EXE.

>> Based on the fact that debug.print will not be executed in a compiled EXE,
>I
>> do the following:

>> In a form, add command1:

>> Option Explicit

>> Private bCompiledEXE As Boolean

>> Private Sub IsCompiledEXE()
>>     bCompiledEXE = True
>>     Debug.Print IsCompiledEXECallback
>> End Sub

>> Private Function IsCompiledEXECallback() As String
>>     bCompiledEXE = False
>> End Function

>> Private Sub Command1_Click()
>> If bCompiledEXE Then
>>     MsgBox "This is compiled EXE"
>> Else
>>     MsgBox "This is VB IDE"
>> End If
>> End Sub

>> Private Sub Form_Load()
>>     IsCompiledEXE
>> End Sub

>> However I get "This is VB IDE" even when I run the compiled EXE.

>> Anyone knows a way to do this?

>> TIA.
>> Aristotelis



Tue, 19 Oct 2004 00:49:23 GMT  
 IDE or EXE? now that's the question

Quote:

> Method 3)

> On Error Resume Next
> Debug.Print 1/0
> If Err Then MsgBox "IDE Mode !"

> Method nicked from Rick Rothstein

A beautiful solution!

Yaniv.

[snip]



Tue, 19 Oct 2004 01:04:49 GMT  
 IDE or EXE? now that's the question
Not bad :-)


Quote:
> Method 3)

> On Error Resume Next
> Debug.Print 1/0
> If Err Then MsgBox "IDE Mode !"

> Method nicked from Rick Rothstein

> On Thu, 02 May 2002 15:40:28 GMT, "Ivan Demkovitch"

> >From MSDN:
> >There are two methods you can use to determine if your program is running
> >from the IDE or the EXE.

> >Method 1: EXE File Name Differs from Project Name
> >The App object contains general information about the program, such as
the
> >executable file name. If the project name and the compiled version of the
> >project have different file names, then you can use the App.EXEName
property
> >to determine if the EXE is running or if your project is running in the
IDE.
> >If the program is running from the Visual Basic IDE, the EXEName property
> >returns the project name. When a program is running from an executable,
the
> >EXEName property contains the EXE file name.

> >Method 2: EXE File Name and the Project Name Are the Same
> >If the project name and the compiled version share the same name, then
use
> >the GetModuleFileName API function to determine if your program is
running
> >from the IDE or from a compiled version. GetModuleFileName retrieves the
> >full path and filename for the executable file containing the specified
> >module. If the function returns a path to the Visual Basic file, VB5.EXE,
> >then the program is running in the IDE. Otherwise, the program is running
> >from an executable file.

> >GetModuleFileName requires the following arguments:

> >  a.. hModule: the handle to the module whose filename you want. Use the
> >hInstance property of the APP object for this parameter.

> >  b.. lpFilename: a pointer to buffer to receive module path. Create a
> >string variable 255 characters long and pass that variable for this
> >parameter.

> >  c.. nSize: the size of buffering characters. Use 255 for this
parameter.

> >The next section illustrates how to create a sample project that
implements
> >both of these methods.

> >Sample Project
> >  1.. Start a new Standard EXE project in Visual Basic. Form1 is created
by
> >default.

> >  2.. Add two CommandButtons to Form1.

> >  3.. Copy the following code to the Code window of Form1:

> >      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 Form_Load()
> >         'Set the command button names
> >         Command1.Caption = "Different Project and Executable Names"
> >         Command2.Caption = "Similar File Names"
> >      End Sub

> >      Private Sub Command1_Click()
> >          'Click this button if the project name and the compiled file
> >          'name are different.
> >          MsgBox VB.App.EXEName
> >      End Sub

> >      Private Sub Command2_Click()
> >         'Click this button if the project name and the compiled file
> >         'name are the same.

> >         Dim strFileName As String
> >         Dim lngCount As Long

> >         strFileName = String(255, 0)
> >         lngCount = GetModuleFileName(App.hInstance, strFileName, 255)
> >         strFileName = Left(strFileName, lngCount)

> >         If UCase(Right(strFileName, 7)) <> "VB5.EXE" Then
> >             MsgBox "Compiled Version"
> >         Else
> >             MsgBox "IDE Version"
> >         End If
> >      End Sub

> >  4.. Save the project with the IDEApp project name.

> >  5.. Compile two different executable files from this project. Use the
> >default file name, IDEApp.exe, for the first executable file. For the
second
> >executable file, use the file name EXEApp. To compile the project,
complete
> >the following steps:

> >    a.. From the File menu, click Make IDEApp.exe. The Make Project
dialog
> >box appears.

> >    b.. Use the default file name or type your file name in the File name
> >text box.

> >    c.. Click OK to create the executable file and to close the Make
project
> >Dialog box.

> >  6.. On the Run menu, click Start or press the F5 key to start the
program.
> >Click the Different Project and Executable Names button. A message box
> >displays with the message, "IDEApp," to indicate that the program is
running
> >from the IDE. Click the Similar File Names button. A message box displays
> >with the message, "IDE Version," to indicate the program is running from
the
> >IDE. Close down the project.

> >  7.. Run either executable file and click the CommandButtons. A message
box
> >is shown indicating the program is running from an executable file.

> >REFERENCES
> >For information about determining if a 16-bit Visual Basic application is
> >running in the design environment, please see the following article in
the
> >Microsoft Knowledge Base:

> >  Q118819 : HOWTO: Tell Whether an App Runs in VB Design Environment



> >> I try to find a reliable way to distinguish the app instances between
VB
> >IDE
> >> and compiled EXE.

> >> Based on the fact that debug.print will not be executed in a compiled
EXE,
> >I
> >> do the following:

> >> In a form, add command1:

> >> Option Explicit

> >> Private bCompiledEXE As Boolean

> >> Private Sub IsCompiledEXE()
> >>     bCompiledEXE = True
> >>     Debug.Print IsCompiledEXECallback
> >> End Sub

> >> Private Function IsCompiledEXECallback() As String
> >>     bCompiledEXE = False
> >> End Function

> >> Private Sub Command1_Click()
> >> If bCompiledEXE Then
> >>     MsgBox "This is compiled EXE"
> >> Else
> >>     MsgBox "This is VB IDE"
> >> End If
> >> End Sub

> >> Private Sub Form_Load()
> >>     IsCompiledEXE
> >> End Sub

> >> However I get "This is VB IDE" even when I run the compiled EXE.

> >> Anyone knows a way to do this?

> >> TIA.
> >> Aristotelis



Tue, 19 Oct 2004 02:15:07 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. VB6 IDE closes during error and can't make exe

2. ide 'feature'?

3. Mouse Wheel doesn't work in Visual Studio's IDE enviornment...HELP

4. Compiled EXE Slower Than IDE!?!?

5. Determine if running in IDE or from EXE

6. inside IDE ok, fails as EXE - PANIC!

7. GPF in Krnl386.exe crashes VB5 IDE on unload of MDI child form

8. krnl386.exe GPF crashes VB5 IDE on MDI child unload

9. API mciSendString OK in ide mode, fails as exe

10. How to tell if IDE or EXE

11. Running from exe or IDE

12. Compiled EXE Slower Than IDE!?!?

 

 
Powered by phpBB® Forum Software