Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

program execution environment? 4

Status
Not open for further replies.

Idiota

Programmer
Dec 18, 2002
11
0
0
AR
Hi.
I need to know if my vb6 program is running from the vb environment (using the run command or the F5 key) or if it is running from the exe file.

Is there any way to know it?

Thank you very much

Daniel
 
This is from msdn

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)) <> &quot;VB5.EXE&quot; Then
MsgBox &quot;Compiled Version&quot;
Else
MsgBox &quot;IDE Version&quot;
End If
End Sub

Peter Meachem
peter @ accuflight.com

 
To much API for no use :)

Use this:

Private Function InIDE() As Boolean
On error Goto ImInIDE

Debug.Print 3/0
InIde = False
Exit Function

ImInIDE:
InIDE = True
End Function

Only in the IDE the Debug.Print expressions are evaluated so as Exe the Debug.Print doesn't exist and doesn't trigger an error...
 
I loved the debug trick when I first saw it, and I still love it. Have a star for...
 
Thank you very much for the stars... Have to figure out what to do with them but they look nice :D
 
Thank you very much, PeterMeachem & IWarez!
IWarez, I loved it! Have a star.

Daniel
 
wow, a bunch of stars for that one there Iwarez... but I'm still in question of WHY anybody wouldn't know if they were running their app from an executable or not. Somebody tell me how this would ever be an issue. This isn't a flame, I just can't figure out the point on this one.

Tuna - It's fat free until you add the Mayo!
 
Tuna, you may need to take different actions if in design mode. For instance I had a recent app that, amongst other things, sent a set of text messages. Once that bit worked, I didn't really want to send the whole lot every time in IDE.

Me, being thick, just Remmed that bit out, but I could have used this much cleverer system if I'd thought of it!
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
I use the InIDE function for several things.

For example:
- Functions like Createmutex for prev instance checking I don't want to be executed in design time. (I know BTW of the App.Previntance function, I just don't want to use it)
- Subclassing I don't always want to use within the IDE. Once it works I disable it inside the IDE for more stability.
- Low level keyboard hooks I disable within the IDE. (I use it to disable the Windows key and Alt-Tab)
- Password screens are very nice within an application, but do you want to be bothered everytime you enter a password protected section of your program?
 
I see... Duh,for a minute there, Tuna was thinking like a goldfish... and as we all know, goldfish have an attention span of 1.2 seconds.

;) Tuna - It's fat free until you add the Mayo!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top