Executing .exe from Visual Basic 6

余生长醉 提交于 2020-02-28 07:19:17

问题


I'm new to visual basic. I'm trying to execute .exe file from VB. But I'm not getting the output. My .exe is having command line args. Following is my code

Private Sub Command1_Click()

    Shell "D:\FEP\extractFEPData.exe data.txt", vbNormalFocus

End Sub

In cmd prompt If I give command extractFEPData.exe data.txt It is parsing the file. But in VB after clicking command button nothing happens.

Please help me.


回答1:


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 Label1_Click()

    ShellExecute Me.hwnd, "Open", "G:\PN Technologies\VB\Krishna & Co\KrishnaCo.exe", vbNullString, "C:\", SW_SHOWNORMAL

End Sub



回答2:


In the past I've always used the ShellExecute Win32 API. You can find a great references on using it from VB6 below.

http://support.microsoft.com/kb/238245

http://www.vbaccelerator.com/codelib/shell/shellex.htm




回答3:


(Assuming you want to capture the output)

You need to use some .NET functions (see here) if you are using VB.NET or some win32 API (see here) if you are using VB6.




回答4:


You can do this using the WShell.Exec method to run the program and return a WshScriptExec object that has a StdOut property which is a TextStream object you can read.

This can be a little clunky since it only supports blocking calls. However you can use API calls to run the external process and redirect its standard I/O streams to anonymous pipes that the VB6 program can read from/write to. This is more work but you get more control.

Perhaps you are looking for something else though?




回答5:


Do you need to set the current directory? You are only passing the file name, not a full path.

ChDrive "d:" 
ChDir "d:\fep" 
Shell "D:\FEP\extractFEPData.exe data.txt", vbNormalFocus 

VB6 Manual



来源:https://stackoverflow.com/questions/4007537/executing-exe-from-visual-basic-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!