Results 1 to 13 of 13

Thread: Get Vb6 to launch an EXE file?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    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!

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Get Vb6 to launch an EXE file?

    Break out the documentation and look up the Shell() function.

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Get Vb6 to launch an EXE file?

    Or simply search this forum for ShellExecute. Tons of examples
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    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:
    1. Option Explicit
    2.  
    3. 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
    4.  
    5. Const SW_SHOW = 5


    But then I get an "argument not optional" error highlighting the program run code.

    VB Code:
    1. 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?

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    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.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    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?

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    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?

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    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?

  12. #12
    Junior Member
    Join Date
    Dec 2013
    Posts
    18

    Re: Get Vb6 to launch an EXE file?

    Quote Originally Posted by Justin M View Post
    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.

  13. #13
    Addicted Member Wolfgang Enzinger's Avatar
    Join Date
    Apr 2014
    Location
    Munich, Germany
    Posts
    160

    Re: Get Vb6 to launch an EXE file?

    Quote Originally Posted by Justin M View Post
    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
  •  



Click Here to Expand Forum to Full Width