2013-07-17 179 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