2013-07-17 180 views
1

在这个例子中是否可以从processPath返回参数?
这可能会更有意义,对不起。从vb.net的命令行获取参数

Dim processName As String 

Dim processPath As String 

If processName = "cmd" Then 
    Dim arguments As String() = Environment.GetCommandLineArgs() 
    Console.WriteLine("GetCommandLineArgs: {0}", String.Join(", ", arguments)) 
End If 
+1

你问[如何获得命令一些其他已经运行的进程的线参数](http://blogs.msdn.com/b/oldnewthing/archive/2009/11/25/9928372.aspx)? – GSerg

+0

是的,确切!我试图阅读你提供的链接,但我并不完全理解它。我会再读一遍。谢谢。 –

+0

该链接解释了为什么你不应该首先这样做。但是,如果您必须运行[.NET WMI工具]提供的WMI查询(http://msdn.microsoft.com/zh-cn/library/ms257340.aspx)。 – GSerg

回答

4

一个简单的(干净)的方式来完成,这将是只修改Sub Main如下,

Sub Main(args As String()) 
    ' CMD Arguments are contained in the args variable 
    Console.WriteLine("GetCommandLineArgs: {0}", String.Join(", ", args)) 
End Sub 
+0

谢谢。但这是否工作: (ByRef currentProcessList()As Process)? –

0

另一种选择

Sub WhatEver() 
    Dim strArg() as string 
    strArg = Command().Split(" ") 
    ' strArg(0) is first argument and so on 
    ' 
    ' 
End Sub