Link to home
Start Free TrialLog in
Avatar of Zdavander
ZdavanderFlag for United States of America

asked on

Linking command buttons to an exe on a cd

I burned 6 software App on a CD, I'm always installing the same ones on clients systems so instead of swapping out 6 CD's one after the other. I got the idea to do the Autorun.inf file & the shell command to be able to allow right-click & chose which app to install, then i got cocky & wanted to do a little autorun exe "menu" which would have 6 command buttons each linked to the "folder\setup.exe" to launch the app. With the VB "menu" app on the CD what path do i tell the shell command to find the exe in a folder on the same cd. As the drive will not always be D: Or E: etc.
I don't even know what terms to use to google the question. The research has been fun though & think i may try to learn more.
Avatar of CleffedUp
CleffedUp
Flag of United States of America image

Being as your autorun.exe will be running from the CD, you need only use the relative path to your apps...  The code below will fire up notepad, minimize the form, wait for notepad to close, then restore the form.

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long

Private Const STATUS_PENDING = &H103&
Private Const PROCESS_QUERY_INFORMATION = &H400

Private Sub Form_Load()
Dim hProcessID&, hProcess&
Dim lngExitCode

    hProcessID = Shell("notepad.exe", vbNormalFocus)
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, hProcessID)
    Form1.WindowState = 1
    Do
        Call GetExitCodeProcess(hProcess, lngExitCode)
        DoEvents
    Loop While lngExitCode = STATUS_PENDING
    Form1.WindowState = 0
End Sub
Just realized I didn't tie the code to the button.  Let's try this again...


Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long

Private Const STATUS_PENDING = &H103&
Private Const PROCESS_QUERY_INFORMATION = &H400

Private Sub Command1_Click()
    ExecAndWait("notepad.exe")
end sub

Private Sub ExecAndWait(strApp)
Dim hProcessID&, hProcess&
Dim lngExitCode

   hProcessID = Shell(strApp, vbNormalFocus)
   hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, hProcessID)
   ' Disable all other buttons here
   Form1.WindowState = 1
   Do
       Call GetExitCodeProcess(hProcess, lngExitCode)
       DoEvents
   Loop While lngExitCode = STATUS_PENDING
   ' Enable all other buttons here
   Form1.WindowState = 0
End Sub
Avatar of Zdavander

ASKER

CleffedUp, Way over my head, i thought it would be;

Private Sub Command3_Click()
Shell ("*:\Rox5 \launch.exe")
End Sub

Where * is the CD drive, I've already made the GUI w/ the 6 command buttons in VB6, below is the autorun.inf file which loads the vb GUI menu i did, when the cd is inserted, then when i click command3 i want it to run the lanch.exe in the Rox5 folder on the CD & so on for the rest. Not sure what to even do w/ the code you wrote above, i was thinking this was a one line of code for each button kind of thing. If i'm just not getting at this from the right angle let me know

[AutoRun]
Open=Menu.exe
Shell\NAV2003=NAV2003
Shell\NAV2003\Command=NAV\setup.exe
Shell\Roxio5=Roxio5
Shell\Roxio5\Command=Rox5\launch.exe
Shell\InterVideo=InterVideo
Shell\InterVideo\Command=Inter\setup.exe
Shell\WinDVD=WinDVD
Shell\WinDVD\Command=Windvd\setup.exe
Shell\Acrobat=Acrobat
Shell\Acrobat\Command=ar505enu.exe
Shell\NAV2002=NAV2002
Shell\NAV2002\Command=NAV2\setup.exe
ASKER CERTIFIED SOLUTION
Avatar of CleffedUp
CleffedUp
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh, I did not know about that (to much infomation can be dangerous), i thought the running app would take over... but the focus back to the menu when done is perfect i really like that.
 As other posts say "i'm a newbie" I AM NOT even a newbie, I messed around w/ basic back in '84-'86, made a duck hunt game, and a lot of "if then goto" stuff.
I'll put it together, thanks for the help.
No problem, glad to help.  Happy installing!
I'm getting a snag w/ the path run time 53 file not found w/ Shell ("\folder\app.exe"), if I code for the root, shell("app.exe") & empty the folder onto the CD the app comes back w/ an install error, which it does not do if I right-click the drive & install w/ the
Shell\app=app
Shell\app\Command=folder\app.exe
in autorun.inf
Forget it I got it.
When I try & use the code you 1st wrote, I'm sure I'll be back.
Again thanks.