ConsoleApplicationBase.CommandLineArgs 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取包含命令行参数作为当前应用程序的字符串的集合。
public:
property System::Collections::ObjectModel::ReadOnlyCollection<System::String ^> ^ CommandLineArgs { System::Collections::ObjectModel::ReadOnlyCollection<System::String ^> ^ get(); };
public System.Collections.ObjectModel.ReadOnlyCollection<string> CommandLineArgs { get; }
member this.CommandLineArgs : System.Collections.ObjectModel.ReadOnlyCollection<string>
Public ReadOnly Property CommandLineArgs As ReadOnlyCollection(Of String)
属性值
String一个 ReadOnlyCollection<T> ,包含命令行参数作为当前应用程序的字符串。
示例
此示例使用 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
注解
该 My.Application.CommandLineArgs 属性为未部署 ClickOnce 的应用程序提供对当前应用程序的命令行参数的只读访问权限。
对于单实例应用程序,该 My.Application.CommandLineArgs 属性返回应用程序的第一个实例的命令行参数。 若要访问后续尝试启动单实例应用程序的参数,必须处理 StartupNextInstance 事件并检查 CommandLine 参数的属性 StartupEventArgs 。
注释
该 My.Application.CommandLineArgs 属性仅返回命令行参数。 这不同于属性的行为,该属性 CommandLine 除了返回参数外还返回应用程序名称。
注释
在已部署 ClickOnce 的My.Application.Deployment应用程序中,使用ActivationUri对象的属性获取命令行参数。 有关详细信息,请参阅 Deployment。
下表列出了涉及 My.Application.CommandLineArgs 该属性的任务的示例。
| 到 | 请参阅 |
|---|---|
| 检查后续尝试启动单实例应用程序的命令行参数 | StartupNextInstance |
按项目类型提供可用性
| 项目类型 | 可用 |
|---|---|
| Windows 应用程序 | 是的 |
| 类库 | 否 |
| 控制台应用程序 | 是的 |
| Windows 控件库 | 否 |
| Web 控件库 | 否 |
| Windows 服务 | 是的 |
| 网站 | 否 |