3

我有一个带有此代码的按钮

Process.Start("start system\now.exe")

现在我想从 Texbox 传递参数,但我不知道如何。我试过了 :

Process.Start("system\now.exe -connect -ip 127.0.0.1 -PORT 910 " & "-USER " & TextBox1.Text & "-PWD " & TextBox1.Text " -serial x4r7680")

但似乎不起作用。有什么想法吗?

4

3 回答 3

3

您需要传入带有参数的 ProcessStartInfo 对象。有关ProcessStartInfo类的信息,请参阅 MSDN 文档中的页面。

根据对文档的粗略阅读,您的示例如下所示:

Dim startInfo as ProcessStartInfo("system\now.exe")
startInfo.Arguments = "-connect -ip 127.0.0.1 -PORT 910 " & "-USER " & TextBox1.Text & "-PWD " & TextBox1.Text " -serial x4r7680"
Process.Start(startInfo)
于 2013-05-24T06:49:47.263 回答
2

查看ProcessStartInfo类。一个例子:

Dim startInfo As New ProcessStartInfo("IExplore.exe")
startInfo.WindowStyle = ProcessWindowStyle.Minimized

Process.Start(startInfo)

startInfo.Arguments = "www.northwindtraders.com"

Process.Start(startInfo)

但您也可以使用Start方法的另一个重载来传递命令行参数。再举个例子:

' Start a Web page using a browser associated with .html and .asp files.
Process.Start("IExplore.exe", "C:\myPath\myFile.htm")
Process.Start("IExplore.exe", "C:\myPath\myFile.asp")

或者在你的情况下:

Process.Start("system\now.exe","-connect -ip 127.0.0.1 -PORT 910 " & "-USER " & TextBox1.Text & "-PWD " & TextBox1.Text " -serial x4r7680")

或者

将 startInfo 调暗为新 ProcessStartInfo("system\now.exe")

Process.Start(startInfo)

startInfo.Arguments = "-connect -ip 127.0.0.1 -PORT 910 " & "-USER " & TextBox1.Text & "-PWD " & TextBox1.Text " -serial x4r7680"

Process.Start(startInfo)

如果包含空格,则需要小心TextBox1.Text(取决于您的程序如何解析命令行选项),除非您将它们括在引号中,否则您最终可能会错误地解析它们。

于 2013-05-24T06:49:27.903 回答
0

Ok, Im sure the problem you have are the quotes "" of the parameters. This example is using argument parameters.

Try with this:

Process.Start("system\now.exe", """" & "-connect -ip 127.0.0.1 -PORT 910 " & "-USER " & lblSubirLlamadasTimeInterval.Text & "-PWD " & lblSubirLlamadasTimeInterval.Text & "-serial x4r7680""")
于 2013-05-24T06:53:27.183 回答