?
Solved

Visual Basic Shell Command

Posted on 2003-03-18
8
Medium Priority
?
433 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

777 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