摘要:[VB.NET] 命令列引數 Environment 使用方法
最近在寫 Console 的專案,有些參數取的根From的方法不一樣
查了一下寫在這邊以防以後要用到。
取得參數:
Dim arg() As String = Microsoft.VisualBasic.Command().Split(" ")
其他人整理過的:
String[] arguments = Environment.GetCommandLineArgs();
Console.WriteLine("取得命令列引數的值: {0}", String.Join(", ", arguments));
Console.WriteLine("處理序的命令列: {0}", Environment.CommandLine);
Console.WriteLine("工作目錄的完整路徑: {0}", Environment.CurrentDirectory);
Console.WriteLine("處理序的結束代碼: {0}", Environment.ExitCode);
Console.WriteLine("是否正常關機: {0}", Environment.HasShutdownStarted);
Console.WriteLine("NetBIOS名稱: {0}", Environment.MachineName);
Console.WriteLine("換行: {0} 第一行{0} 第二行{0} 第三行", Environment.NewLine);
Console.WriteLine("作業系統: {0}", Environment.OSVersion.ToString());
Console.WriteLine("堆疊追蹤資訊: '{0}'", Environment.StackTrace);
Console.WriteLine("系統目錄完整路徑: {0}", Environment.SystemDirectory);
Console.WriteLine("系統啟動後的毫秒數: {0}", Environment.TickCount);
Console.WriteLine("使用者網域名稱: {0}", Environment.UserDomainName);
Console.WriteLine("處理序是否與使用者互動: {0}", Environment.UserInteractive);
Console.WriteLine("使用者名稱: {0}", Environment.UserName);
Console.WriteLine("Version: {0}", Environment.Version.ToString());
Console.WriteLine("實際記憶體數量: {0}", Environment.WorkingSet);
String query = "本機目錄 %SystemDrive% 與本機根目錄 %SystemRoot%";
str = Environment.ExpandEnvironmentVariables(query);
Console.WriteLine("ExpandEnvironmentVariables: {0} {1}", nl, str);
Console.WriteLine("環境變數: {0} 暫存目錄 {1}.", nl,
Environment.GetEnvironmentVariable("TEMP"));
Console.WriteLine("環境變數: ");
IDictionary environmentVariables = Environment.GetEnvironmentVariables();
foreach (DictionaryEntry de in environmentVariables)
{
Console.WriteLine(" {0} = {1}", de.Key, de.Value);
}
Console.WriteLine("系統特殊資料夾的路徑: {0}", Environment.GetFolderPath(Environment.SpecialFolder.System));
String[] drives = Environment.GetLogicalDrives();
Console.WriteLine("系統磁碟機: {0}", String.Join(", ", drives));
參考:
http://msdn.microsoft.com/zh-tw/library/system.environment.aspx
以上文章敘述如有錯誤及觀念不正確,請不吝嗇指教
如有侵權內容也請您與我反應~謝謝您 :)