Shell Problem with command line arguments VB6
Hi
I am new to VB6 programming.
I am stuck with Shell command. I want to run a EXE with command line arguments i.e.
Shell ("c:\myapplication.exe argument1 argument2") but it does not work. Project runs but nothing happens.
When i run it without any arguments i.e.
Shell ("c:\myapplication.exe") it works.
Please help ASAP and tell me a way out Please.
regards
SAM
PS:And if I run it in Windows->Start->Run as c:\myapplication.exe argument1 argument2 the also it works fine.
Re: Shell Problem with command line arguments VB6
I don't think the Shell function supports arguments maybe try using the ShellExecute API.
Re: Shell Problem with command line arguments VB6
Thanks
Do u have any codes that can solve my problem ?
thanks
Re: Shell Problem with command line arguments VB6
vb Code:
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
Private Sub Button1_Click()
ShellExecute "app.path and file ....... arguments etc...."
End Sub
Re: Shell Problem with command line arguments VB6
Thanks a lot for the code but it somehow didnt work. I am sure i am putting some wrong syntax.
When I tried is as below then it didn't work
ShellExecute "c:\myapplication.exe argument1 argument2 "
Could uou please write a proper syntax for it.
I want to run exactly like this i.e.
c:\myapplication.exe argument1 argument2
Many thanks
Sam
Re: Shell Problem with command line arguments VB6
Have a look at this article.
Re: Shell Problem with command line arguments VB6
Its best if you add some kind of delimiter to your arguments. ;)
Code:
Option Explicit
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
Private Const SW_HIDE As Long = 0
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWMINIMIZED As Long = 2
Private Sub Command1_Click()
ShellExecute Me.hwnd, "runas", "C:\MyFile.exe", "/Arg1 /Arg2", "C:\", SW_SHOWNORMAL
End Sub