What is the VB 6 equivalent of Process.Start?

2020-03-26 04:14发布

问题:

I am stuck on a really stuck with this one line. In vb.net this is easy, but how do I do this in vb6? Tried to search from google for few hours and got nothing. Feels almost embrassing.

Here's the code. (.NET)

Process.Start("runme.exe", " -parameter1 " & "-parameter2 " & "-parameter3")

I want to run EXE, from the same directory as where the program is, with parameters. I am sure there is some very simple solution, but I can't get it to work. Any help would be appreciated.

回答1:

You can use Shell and ShellExecute

Shell "c:\runme.exe", vbNormalFocus

http://msdn.microsoft.com/en-us/library/aa242087(v=vs.60).aspx



回答2:

Just call Shell, and the parameters should be passed also with the string of the .exe name, like this:

Call Shell("""runme.exe"" ""-parameter1 "" ""-parameter2""", vbNormalFocus)

PS: The quotes make the difference, dont ignore it :)



回答3:

You can use ShellExecute for this:

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

ShellExecute 0, "open", App.Path & "\runme.exe", "-parameter1 -parameter2 -parameter3", vbNullString, vbNormalFocus 

I have found that using Shell causes a delay in the calling program waiting for the return value, whereas ShellExecute does not.



标签: process vb6