My.Application.CommandLineArgs 属性
更新:2007 年 11 月
获取以字符串形式包含当前应用程序命令行参数的集合。
' Usage
Dim value As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs
' Declaration
Public ReadOnly Property CommandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
返回值
String 的一个 ReadOnlyCollection<T>,以字符串形式包含当前应用程序的命令行参数。
备注
对于未以 ClickOnce 方式部署的应用程序,My.Application.CommandLineArgs 属性提供了对当前应用程序命令行参数的只读访问。
对于单一实例应用程序,My.Application.CommandLineArgs 属性将返回应用程序第一个实例的命令行参数。为了访问之后尝试启动单一实例应用程序的操作的参数,您必须处理 My.Application.StartupNextInstance 事件,并检查 StartupEventArgs 参数的 CommandLine 属性。
说明: |
---|
My.Application.CommandLineArgs 属性只返回命令行参数。这与 CommandLine 属性的行为不同,后者除了参数之外还将返回应用程序名称。 |
说明: |
---|
在以 ClickOnce 方式部署的应用程序中,使用 My.Application.Deployment 对象的 ActivationUri 属性来获取命令行参数。有关更多信息,请参见 My.Application.Deployment 属性。 |
任务
下表列出了涉及 My.Application.CommandLineArgs 属性的任务的示例。
要执行的操作 |
请参见 |
---|---|
检查应用程序是否已使用字符串 /batch 作为参数启动 |
|
检查之后尝试启动单一实例应用程序的操作的命令行参数 |
示例
此示例使用 My.Application.CommandLineArgs 属性来检查应用程序的命令行参数。如果发现了以 /input= 开头的参数,则显示该参数的其余部分。
Private Sub ParseCommandLineArgs()
Dim inputArgument As String = "/input="
Dim inputName As String = ""
For Each s As String In My.Application.CommandLineArgs
If s.ToLower.StartsWith(inputArgument) Then
inputName = s.Remove(0, inputArgument.Length)
End If
Next
If inputName = "" Then
MsgBox("No input name")
Else
MsgBox("Input name: " & inputName)
End If
End Sub
要求
命名空间:Microsoft.VisualBasic.ApplicationServices
**程序集:**Visual Basic 运行库(在 Microsoft.VisualBasic.dll 中)
按项目类型列出的可用性
项目类型 |
可用 |
---|---|
Windows 应用程序 |
是 |
类库 |
否 |
控制台应用程序 |
是 |
Windows 控件库 |
否 |
Web 控件库 |
否 |
Windows 服务 |
是 |
网站 |
否 |
权限
以下权限可能是必需的:
权限 |
说明 |
---|---|
控制访问 PATH 环境变量的能力。关联的枚举:Read。 |
请参见
参考
ConsoleApplicationBase.CommandLineArgs