Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

opening other exe's from VB6

Posted on 2003-02-22
9
Medium Priority
?
266 Views
Last Modified: 2010-05-01
ive been doing a lot of c++ programming and now i have to get back into VB6 cause thats what we are programming with in school.

ive decided to make a few review programs to help me get back into my VB mode.  i want to make a program that will let me choose what game i want to run. the only problem is i cannot remember the syntax for running another exe from VB6, thanks for any help in advance
0
Comment
Question by:Samos
9 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 100 total points
ID: 7998736
Hello Samos,

Shell "FullPathAndFilenameToExecutable Parameters"

for example starting word
 
Shell "C:\Program Files\Microsoft Office\Office\Winword.exe"
or with document like
Shell "C:\Program Files\Microsoft Office\Office\Winword.exe C:\Mydoc.doc"

HAGD:O)Bruintje
0
 
LVL 18

Assisted Solution

by:Sethi
Sethi earned 100 total points
ID: 7998974
There are two of ways by which you can do this.

First Method
Use the Shell Function In VB. Here is an example:
Shell "C:\WINNT\system32\notepad.exe " & strFileName, vbMaximizedFocus
Specify the textfile name with full path in strFileName.


Second Method
Use ShellExecute API.
Public 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
ShellExecute Me.hwnd, "Open", filePath, 0&, 0&, SW_SHOWNORMAL

Specifying Network Path with ShellExecute
strPath = "\\ABC Computer\C\My Documents\Text.txt"
0
 
LVL 18

Expert Comment

by:Sethi
ID: 7998975
There are two of ways by which you can do this.

First Method
Use the Shell Function In VB. Here is an example:
Shell "C:\WINNT\system32\notepad.exe " & strFileName, vbMaximizedFocus
Specify the textfile name with full path in strFileName.


Second Method
Use ShellExecute API.
Public 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
ShellExecute Me.hwnd, "Open", filePath, 0&, 0&, SW_SHOWNORMAL

Specifying Network Path with ShellExecute
strPath = "\\ABC Computer\C\My Documents\Text.txt"
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:Sethi
ID: 7998978
Sorry about two clicks ;)
0
 

Expert Comment

by:pkmnfrk
ID: 7999730
With a listbox on a form, here is the code I would use:

'------Begining of code------

Private games as Collection 'This will hold the names and paths of the games

Private sub Form_Load()

Set games = New Collection 'Create new collection

games.add "<path of your game>", "Name of your game" 'Add as many as you want.

For each game in games 'Loop through the games
list1.add game.key 'Add the name of the game to the list box
next

end sub

private sub list1_DblClick()
Shell games(List1.List(List1.ListIndex)), vbNormalFocus 'Load the game
end sub

'------End of code------

I hope this helps!
0
 

Expert Comment

by:diossito
ID: 8001735
you can do that so...
Shell "Dir\*.exe", vbNormalFocus


or if you don't understandme, there is an example
Shell "C:\Windows\notepad.exe", vbNormalFocus

if you want, you can also add
Common Dialog  (Name: CommonDialog1)
Text box       (Name: txtSource)
Command button (Name: cmdSelect)
Command button (Name: cmdExecute)

And insert the following code:

Private Sub cmdSelect_Click()
    CommonDialog1.Filter = "(*.exe)|*.exe"
    CommonDialog1.ShowOpen
    If CommonDialog1.FileName <> "" Then
        txtSource.Text = CommonDialog1.FileName
    End If
End Sub

Private Sub cmdExecute_Click()
    If txtSource.Text <> "" Then
        Shell txtSource.Text, vbNormalFocus
    End If
End Sub
0
 

Expert Comment

by:diossito
ID: 8001748
You can add the Common Dialog by clicking in Project>Components and there select "Microsoft Common Dialog Control 6.0(SP3)"
0
 

Expert Comment

by:CleanupPing
ID: 8901265
Samos:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8964139
Moderator, my recommended disposition is:

    Split points between: bruintje and Sethi

DanRollins -- EE database cleanup volunteer
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question