从 Visual Basic 6 执行 .exe

发布于 2024-09-28 22:57:55 字数 333 浏览 8 评论 0原文

我是视觉基础的新手。我正在尝试从 VB 执行 .exe 文件。但我没有得到输出。我的 .exe 有命令行参数。以下是我的代码

Private Sub Command1_Click()

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

End Sub

在 cmd 提示符中如果我给出命令 extractFEPData.exe data.txt 它正在解析该文件。但在 VB 中单击命令按钮后没有任何反应。

请帮我。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

柠栀 2024-10-05 22:57:55
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
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
蓦然回首 2024-10-05 22:57:55

过去我一直使用 ShellExecute Win32 API。您可以在下面的 VB6 中找到有关使用它的精彩参考资料。

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

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

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

丘比特射中我 2024-10-05 22:57:55

(假设您要捕获输出)

您需要使用一些 .NET 函数(请参阅此处) 如果您使用的是 VB.NET
或一些 win32 API (参见 此处)如果您使用的是 VB6。

(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.

起风了 2024-10-05 22:57:55

您可以使用 WShell.Exec 方法运行程序并返回具有 StdOut 属性的 WshScriptExec 对象,该属性是您可以读取的 TextStream 对象。

这可能有点笨拙,因为它只支持阻塞调用。但是,您可以使用 API 调用来运行外部进程,并将其标准 I/O 流重定向到 VB6 程序可以读取/写入的匿名管道。这是更多的工作,但你可以获得更多的控制权。

也许您正在寻找其他东西?

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?

千秋岁 2024-10-05 22:57:55

需要设置当前目录吗?您仅传递文件名,而不传递完整路径。

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

VB6 手册

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文