Results 1 to 5 of 5

Thread: start exe from command button

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    start exe from command button

    possible to launch a .exe in eventclikc of commandbutton1?

    Note:
    Exe is a simple vb6 compiled program.
    Is in c:\mydir\myexe.exe

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: start exe from command button

    Shell command?

    Or, in more complex cases ShellExecute API call?
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: start exe from command button

    Quote Originally Posted by Elroy View Post
    Shell command?

    Or, in more complex cases ShellExecute API call?
    ... ShellExecute API call?

    hummmm

    Not experince.

    Simple code, plaase.
    Tks.

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: start exe from command button

    The VB6 built-in "Shell" function may do what you need. However, here's the ShellExecute API ...

    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
    Private Const SW_SHOWMAXIMIZED = 3
    Private Const SW_SHOWNORMAL = 1
    '
    
    Private Sub Command1_Click()
        Dim rtn As Long
        '
    
        Dim sFileSpec As String
        sFileSpec = "Notepad.exe"
    
    
        rtn = ShellExecute(0, "Open", sFileSpec, vbNullString, vbNullString, SW_SHOWNORMAL)
    
    End Sub
    
    
    I just set it up to execute Notepad. However, ShellExecute will also work with file associations. In other words, you could send it a "Something.Docx" file and it'd open it with Word.

    Enjoy,
    Elroy

    EDIT1: For info on Shell, just type in Shell somewhere in your code, and then hit F1 (assuming you have the MSDN installed).
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

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