通过任何命令行参数? [英] Pass any command line Argument?
问题描述
您好,先生,
如何在我的VB应用程序执行时传递任何命令行参数(通过运行命令)
传递,并且在激活表单时会收到值
.
Hello sir,
How, can i pass any command line arguments (Through Run Command)
pass when my VB application execute and that's values
are receive when form activate.
请帮帮我
谢谢.
Kindly Help me
Thanks.
推荐答案
要将命令行参数传递给另一个应用程序,您应该研究一下Process类,它几乎与Windows进程有任何关系.简单的例子:
To pass command line arguments to another app, you should look into the Process class, which does pretty much anything there is to do with Windows processes. Simple example:
暗淡 p 为 新建 进程
p.StartInfo.FileName = "C:\ WINDOWS \ NOTEPAD.EXE"
p.StartInfo.Arguments = "C:\ AUTOEXEC.BAT"
p.Start()
p.WaitForExit()
MsgBox( "记事本已完成..." )
Dim p As New Process
p.StartInfo.FileName = "C:\WINDOWS\NOTEPAD.EXE"
p.StartInfo.Arguments = "C:\AUTOEXEC.BAT"
p.Start()
p.WaitForExit()
MsgBox("You're done with Notepad...")
另一方面,要查看已将哪些命令行参数传递给您的应用程序,请使用My.Application.CommandLineArgs(假设您使用的是VS2005):
On the other hand, to see which command line arguments have been passed to your app, use My.Application.CommandLineArgs (assuming you're using VS2005):
对于 i 为 整数 = 1 至 我的 .Application.CommandLineArgs.Count
For i As Integer = 1 To My.Application.CommandLineArgs.Count
MsgBox( My .Application.CommandLineArgs(i-1))
下一个 i
Next i
在VS2003上,仍然很容易获取命令行参数,但是您需要在Sub Main中这样做,因此,如果您的项目当前是使用表单启动的,则需要使用Project/特性.示例:
On VS2003, it's still quit easy to grab your command line parameters, but you'll need to do so in Sub Main, so if your project currently starts up using a form, you'll need to change that using Project/Properties. Example:
Sub Main( ByVal argv() 为 字符串 )
Sub Main(ByVal argv() As String)
对于 i 为 整数 = 1 收件人 argv.Length
MsgBox(argv(i-1))
下一个 i
Next i
结束 Sub
'//mdb
这篇关于通过任何命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!