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

x
?
Solved

Visual Basic Shell Command

Posted on 2003-03-18
8
Medium Priority
?
437 Views
Last Modified: 2013-11-25
I want to use a Shell command in my VB 6.0 application to start an executable.  I want to pass it four parameters.  Is this possible and if so, how would I do it?
0
Comment
Question by:PJS123
8 Comments
 
LVL 14

Expert Comment

by:aelatik
ID: 8161716
Shell "c:\yourexe.exe"
0
 
LVL 14

Expert Comment

by:aelatik
ID: 8161720
What exactly do you mean with parameters ?

Like Shell "Yourexe.exe /p=blahblah"
0
 

Expert Comment

by:sinistershadow
ID: 8161760
It's exactly the same way you would pass it parameters in the run dialog.

e.g. To open Windows Media Player with a file you would type:

wmplayer.exe C:/File.wav

into a run dialog box (the '.exe' is not necessary)

In VB6 you do the same thing:

Call Shell("wmplayer.exe C:/File.wav")

Hope that helps.

Sinister Shadow
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Accepted Solution

by:
trkcorp earned 300 total points
ID: 8161969
As previously stated,

Shell("your.exe /parm1 /parm2 /parm3 /parm4")

But then, how do you read the parameters? Well, in your start up code for the target exe (most likely your Sub Main()) use the Command function something like this:

Sub Main()
Dim sArray() as string
If Len(Command) > 0 Then
  sArray = Split(Command, , Space(1), 4)
  MsgBox "Parm 1 Value: " & sArray(0)
  MsgBox "Parm 2 Value: " & sArray(1)
  MsgBox "Parm 3 Value: " & sArray(2)
  MsgBox "Parm 4 Value: " & sArray(3)
End If
End Sub



0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8162048
optionally, you could use ShellExecute API:

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


Sub LaunchExe()
shellexceute 0,"open","c:\myfile.exe","parameters goes here",vbnullstring,vbnormal
end sub
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8162087
or
Sub LaunchExe(sExePath as string)
shellexecute 0,"open",sExePath,"parameters goes here",vbnullstring,vbnormal
end sub
0
 

Expert Comment

by:CleanupPing
ID: 8532043
Hi PJS123,
This old question (QID 20555209) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8957235
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

-->Accept trkcorp's comments as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

GPrentice00
EE Cleanup Volunteer
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

578 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