• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

i want to make a program launcher

im so new to visual basic its untrue

i want to make a simple application where i can launch a program from a button

im new to codeing and i was wondering how i would do it

i know its somthing to do with the code under Click() but i dont know how to do it

any help would be cool
if it helps the program i want to run is called soma and its command line is
"c:\soma\soma.exe session.mythofsoma.net"
0
sailormars
Asked:
sailormars
1 Solution
 
NaylinCommented:
Easiest way...


Private Sub Command1_Click()
   Shell "c:\soma\soma.exe session.mythofsoma.net", 1
End sub

Note: VB program remains running in the background.
0
 
DocMCommented:
You can use the Shell Function which runs an executable program and returns a Variant (Double) representing the program's task ID if successful.
Example:
Dim RetVal
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1)    ' Run Calculator.
0
 
KnarfCommented:
Just to clarify the other answers a bit more..

Shell(PathName,WindowStyle)

PathName is the location of the application you want to run

WindowStyle is how you want to window to load.  The following is a list of window styles.

vbHide             0  
Window is hidden and focus is passed to the hidden window.  
vbNormalFocus      1  
Window has focus and is restored to its original size and position.
vbMinimizedFocus   2  
Window is displayed as an icon with focus.
vbMaximizedFocus   3  
Window is maximized with focus.
vbNormalNoFocus    4  
Window is restored to its most recent size and position. The currently active window remains active.
vbMinimizedNoFocus 6  
Window is displayed as an icon. The currently active window remains active.

The Shell() command returns a Double variant which holds the programs Task ID (Also known as PID)
If the operation failed the return value will be 0
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
sailormarsAuthor Commented:
thank you for the help everyone hehe

i couldnt edit the post in time but i would also like to know how to run a website address from a button too


^_^ thanks again
0
 
sailormarsAuthor Commented:
thank you very much ^_^

0
 
DocMCommented:

Place the following in the general declarations area of the form.

#If Win32 Then

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

#Else

Private Declare Function ShellExecute Lib _
"shell.dll" _
(ByVal hwnd As Integer, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Integer) As Integer

#End If

Private Const SW_SHOWNORMAL = 1



Private Sub Command1_Click()

Dim iret As Long

' open URL into the default internet browser

iret = ShellExecute(Me.hwnd, vbNullString, _
"http://www.microsoft.com", vbNullString, _
"c:\", SW_SHOWNORMAL)

End Sub
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now