-
Dec 14th, 2014, 08:23 PM
#1
Thread Starter
PowerPoster
Get Vb6 to launch an EXE file?
Hi there folks! I have seen ways for VB6 to play wav files, but is there a way for VB6 to launch an exe file?
I am working on a program with small educational games for the classroom, but I don't want them all compiled into 1 super big .exe file, so I was thinking when a user clicks on a button, it would launch the exe for the specifically needed app?
Thanks!
-
Dec 14th, 2014, 08:28 PM
#2
Re: Get Vb6 to launch an EXE file?
Break out the documentation and look up the Shell() function.
-
Dec 14th, 2014, 08:30 PM
#3
Re: Get Vb6 to launch an EXE file?
Or simply search this forum for ShellExecute. Tons of examples
-
Dec 14th, 2014, 09:40 PM
#4
Thread Starter
PowerPoster
Re: Get Vb6 to launch an EXE file?
Thank you guys!
So I found an example, but am having some problems executing the code.
So in the top declarations of my app, I have this..
VB Code:
Option Explicit Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long Const SW_SHOW = 5
But then I get an "argument not optional" error highlighting the program run code.
VB Code:
ShellExecute Me.hwnd, "open", App.path & "\ToolBoxApps\MHX Letter Scramble\MHX_Letter_Scramble_NO_INSTALL\MHXLetterScramble.exe", vbNullString, SW_SHOW
Then it will highlight the ShellExecute in that line in blue. Did I miss a declaration?
-
Dec 14th, 2014, 09:50 PM
#5
Re: Get Vb6 to launch an EXE file?
Yep, that API has 6 parameters, you only provided 5.
Right Click on that line and select "Parameter Info" from the popupmenu. Should be able to see what you missed
-
Dec 14th, 2014, 10:04 PM
#6
Re: Get Vb6 to launch an EXE file?
If you are simply running programs then ShellExecute() buys you little over Shell(). Why work so hard for nothing in return?
Worse yet at least Shell() returns a useful value if you need to do "shell and wait" or "shell and poll" operations to detect completion. To get something similar you have to use the even more cumbersome ShellExecuteEx() API call.
You can lead a horse to water, but you can't make him think.
-
Dec 14th, 2014, 10:11 PM
#7
Thread Starter
PowerPoster
Re: Get Vb6 to launch an EXE file?
Awesome. So I missed the ByVal nShowcmd as long. What would that mean I missed as far as opening the .exe? Is that an open to show an open dialog box?
-
Dec 14th, 2014, 10:24 PM
#8
Re: Get Vb6 to launch an EXE file?
When in doubt about APIs, look it up on MSDN and read the page. Better than someone mistakenly giving you bad information.
P.S. That wasn't the parameter you missed. There are 2 Long parameters & 4 Strings. You are missing one of the string parameters
-
Dec 14th, 2014, 10:37 PM
#9
Thread Starter
PowerPoster
Re: Get Vb6 to launch an EXE file?
Thanks for the link.
I thought for sure I had 4 strings. open is 1, the file path is 2, vbNullString is 3, and I thought SW_SHOW was the 4th?
-
Dec 14th, 2014, 10:40 PM
#10
Re: Get Vb6 to launch an EXE file?
SW_Show is not a string, it is numeric constant, it is the command, you are missing the directory parameter, 2nd from last
Const SW_SHOW = 5
-
Dec 14th, 2014, 11:03 PM
#11
Thread Starter
PowerPoster
Re: Get Vb6 to launch an EXE file?
I think I understand now, thanks.
I checked on the link you gave me, it says that if the directory path is with the filename path, I shoudln't need to use it, but if I don't need to use it, what would I include there in its place.
cause the directory path would be App.path & "\ToolBoxApps\MHX Letter Scramble\MHX_Letter_Scramble_NO_INSTALL\
Now, I just tried that (having just the filename , and then the directory path and it works, so thanks for your help. If though I wanted to put both path and filename together, I am wondering what I would put there for the directory path?
-
Dec 15th, 2014, 07:43 AM
#12
Junior Member
Re: Get Vb6 to launch an EXE file?
Originally Posted by Justin M
I am wondering what I would put there for the directory path?
maybe you are aware of the "StartIn" - Folder if you create a shortcut.
The passed path is nothing else. The path could be validated within a vb6 application with app.Path.
This allows you to start a process in Folder A - but the process use Folder B as application folder.
If this is not required .. use the real folder of the process.
-
Dec 15th, 2014, 07:55 AM
#13
Re: Get Vb6 to launch an EXE file?
Originally Posted by Justin M
I checked on the link you gave me, it says that if the directory path is with the filename path, I shoudln't need to use it, but if I don't need to use it, what would I include there in its place.
Just another vbNullString would do:
Code:
ShellExecute Me.hWnd, "open", App.Path & "\ToolBoxApps\MHX Letter Scramble\MHX_Letter_Scramble_NO_INSTALL\MHXLetterScramble.exe", vbNullString, vbNullString, SW_SHOW
Wolfgang
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
|