|
-
Feb 21st, 2013, 12:05 PM
#1
Thread Starter
Junior Member
[RESOLVED] Get the File Name of the Running VB6 Application.
Hey all,
I have an application I've built and I want to increment the revision numbers on it just by changing the File Name of the compiled executable.
My hopes were to have my program look at the compiled executable (which is itself) then take the name and put it into my main form's caption.
This would allow the revision number to be displayed on the form's caption (without needed to update that part as well). Yay Automation!
So, I'd like to ask, is there a way where I can retrieve the File Name of the application that is running?
Thanks much, your help is greatly appreciated!
God Bless,
-Nick
-
Feb 21st, 2013, 12:15 PM
#2
Re: Get the File Name of the Running VB6 Application.
Code:
Option Explicit
Private Sub Form_Load()
Me.Caption = App.EXEName
End Sub
-
Feb 21st, 2013, 12:50 PM
#3
Thread Starter
Junior Member
Re: Get the File Name of the Running VB6 Application.
Although App.EXEName looks good, this isn't what I'm looking for. App.EXEName is referencing the executable's title (defined in the projects properties), and not it's file name.
Even though when compiling I could use the title to do the version incrementing, I would really like to use the file name. (As this can be done outside of VB6 IDE)
Thanks though!
-
Feb 21st, 2013, 01:00 PM
#4
Re: Get the File Name of the Running VB6 Application.
You could get all files of your App.Path and match the .exe matching your application's name then simply put that .exe file's name for you form's caption.
I don't see why just do it the original way, updating it in your Project properties, would be the simplest way.
-
Feb 21st, 2013, 01:01 PM
#5
Re: Get the File Name of the Running VB6 Application.
There is an api getmodulename i think, but you would need the process-id of your app
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Feb 21st, 2013, 01:04 PM
#6
Re: Get the File Name of the Running VB6 Application.
In the event that your exe's filename has Unicode characters in it, the following function will help you deal with VB's mostly ANSI-only limitation:
Code:
Private Declare Function GetModuleFileNameW Lib "kernel32.dll" (ByVal hModule As Long, ByVal lpFilename As Long, ByVal nSize As Long) As Long
Private Function GetEXEName() As String
Const MAX_PATH = 260&
GetEXEName = Space$(MAX_PATH - 1&)
GetEXEName = Left$(GetEXEName, GetModuleFileNameW(0&, StrPtr(GetEXEName), MAX_PATH))
GetEXEName = Right$(GetEXEName, Len(GetEXEName) - InStrRev(GetEXEName, "\"))
End Function
Private Sub Form_Load()
Caption = GetEXEName
End Sub
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Feb 21st, 2013, 01:06 PM
#7
Re: Get the File Name of the Running VB6 Application.
 Originally Posted by Millerni456
Although App.EXEName looks good, this isn't what I'm looking for. App.EXEName is referencing the executable's title (defined in the projects properties), and not it's file name.
Even though when compiling I could use the title to do the version incrementing, I would really like to use the file name. (As this can be done outside of VB6 IDE)
Thanks though!
That is not actually the case. I just tested it here. I created a project and used the following code
Code:
Option Explicit
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Load()
Me.Caption = App.EXEName
End Sub
The project properties are set to project1
I compiled as MyTest.Exe
I run the program and the caption reads MyTest.Exe
I renamed the exe to MyTest2.Exe
I run the program and the caption reads MyTest2.Exe
I renamed it to BogusProgram.Exe and again it reads BogusProgram.Exe
So it would appear that this does indeed give you the actual exe name of the running program and not what is set in the properties.
You should have tried it before you dismissed it.
-
Feb 21st, 2013, 01:08 PM
#8
Thread Starter
Junior Member
Re: Get the File Name of the Running VB6 Application.
 Originally Posted by Max187Boucher
You could get all files of your App.Path and match the .exe matching your application's name then simply put that .exe file's name for you form's caption.
I don't see why just do it the original way, updating it in your Project properties, would be the simplest way.
When listing all of the files and searching for an executable, are there ways of confirming that the .exe being looked at matches the app?
Suppose I had two .exe's in the directory where my program was ran; I'd get two possible file names that could be used. How can I distinguish which is the one I'm interested in?
-
Feb 21st, 2013, 01:17 PM
#9
Thread Starter
Junior Member
Re: Get the File Name of the Running VB6 Application.
 Originally Posted by DataMiser
So it would appear that this does indeed give you the actual exe name of the running program and not what is set in the properties.
You should have tried it before you dismissed it.
Surprisingly enough, I attempted that with no success. After reading your post I tried again and it works! :P
To be honest, I think I tricked myself since I had modified the exe title to what I wanted it to be (containing the version#), and I had my file named the same way. Thus, I was unable to draw out where the reference came from.
Thanks for re-iterating this solution! 
God Bless,
-Nick
-
Feb 21st, 2013, 01:21 PM
#10
Re: [RESOLVED] Get the File Name of the Running VB6 Application.
No prob 
Now if only I could figure out why my emulator is not working
-
Feb 21st, 2013, 09:28 PM
#11
Re: Get the File Name of the Running VB6 Application.
 Originally Posted by Millerni456
Although App.EXEName looks good, this isn't what I'm looking for. App.EXEName is referencing the executable's title (defined in the projects properties), and not it's file name.
Not a true statement - App.EXEName returns executable file name. This is easy enough to test:
- create new project and keep all default names (form1, Project1, etc)
- add that sample code I posted
- save project (keep the default names)
- compile it and name executable say "test"
- run the exe - you should see "test" in the form's title bar (caption)
Open the project and check its properties - you will still see the Project1...
Last edited by RhinoBull; Feb 21st, 2013 at 09:32 PM.
-
Jan 13th, 2014, 04:02 PM
#12
Re: Get the File Name of the Running VB6 Application.
 Originally Posted by Bonnie West
In the event that your exe's filename has Unicode characters in it, the following function will help you deal with VB's mostly ANSI-only limitation:
Code:
Private Declare Function GetModuleFileNameW Lib "kernel32.dll" (ByVal hModule As Long, ByVal lpFilename As Long, ByVal nSize As Long) As Long
Private Function GetEXEName() As String
Const MAX_PATH = 260&
GetEXEName = Space$(MAX_PATH - 1&)
GetEXEName = Left$(GetEXEName, GetModuleFileNameW(0&, StrPtr(GetEXEName), MAX_PATH))
GetEXEName = Right$(GetEXEName, Len(GetEXEName) - InStrRev(GetEXEName, "\"))
End Function
Private Sub Form_Load()
Caption = GetEXEName
End Sub
Just as an addition to above code from Bonnie West:
I would also exlude the file extension as the App.EXEName does it. Also check if running in the IDE or not as App.EXEName returns the project name in the IDE and the above code would return "vb6" in that case which is not very meaningful.
Would then be like this:
Code:
Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameW" (ByVal hModule As Long, ByVal lpFileName As Long, ByVal nSize As Long) As Long
Public Function GetEXEName() As String
If InIDE() = False Then
Const MAX_PATH As Long = 260
Dim Buffer As String
Buffer = String(MAX_PATH, vbNullChar)
Buffer = Left$(Buffer, GetModuleFileName(0, StrPtr(Buffer), MAX_PATH + 1))
Buffer = Right$(Buffer, Len(Buffer) - InStrRev(Buffer, "\"))
GetEXEName = Left$(Buffer, InStrRev(Buffer, ".") - 1)
Else
GetEXEName = App.EXEName
End If
End Function
Public Function InIDE(Optional ByRef B As Boolean = True) As Boolean
If B = True Then Debug.Assert Not InIDE(InIDE) Else B = True
End Function
Last edited by Krool; Jan 13th, 2014 at 05:17 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|