1.前言:
Win8的系統命令非常多,在系統中要找到開啟這些服務的位置有時並不好找,為了簡化開啟服務查找的時間,利用C#的Console平台,建立一個互動的平台,可點選數字直接執行常用系統命令來開啟Windows的服務。

2.說明:
開啟Console專案,建立程式碼:

static void Main(string[] args)
{
	Console.WriteLine("Welcome to use open windows service application, type /? for help!");

	while (true)
	{
		string inputString = Console.ReadLine();
		int commandEndIndex = inputString.IndexOf(' ');
		string command = string.Empty;

		if (commandEndIndex > -1)
		{
			command = inputString.Substring(0, commandEndIndex).ToUpper();
		}
		else
		{
			command = inputString.ToUpper();
		}

		switch (command)
		{
			case "/?":
				{
					Console.WriteLine("/? 功能說明");
					Console.WriteLine("/CLS 清除螢幕");
					Console.WriteLine("/QUIT 離開系統");
					Console.WriteLine("輸入以下數字並按下Enter鍵。");
					Console.WriteLine("-----------------------------------------------");
					Console.WriteLine("開啟【小畫家】請輸入 1");
					Console.WriteLine("開啟【計算機】請輸入 2");
					Console.WriteLine("開啟【放大鏡】請輸入 3");
					Console.WriteLine("開啟【程式和功能】請輸入 4");
					Console.WriteLine("開啟【網路連線】請輸入 5");
					Console.WriteLine("開啟【ODBC資料來源管理員】請輸入 6");
					Console.WriteLine("開啟【自黏便籤】請輸入 7");
					Console.WriteLine("開啟【記事本】請輸入 8");
					Console.WriteLine("開啟【電腦管理】請輸入 9");
					break;
				}
			case "/CLS":
				{
					Console.Clear();
					Console.WriteLine("Welcome to use open windows service application, type /? for help!");
					break;
				}
			case "/QUIT":
				{
					return;
				}
			case "1":
				{
					System.Diagnostics.Process p = new System.Diagnostics.Process();
					p.StartInfo.FileName = "cmd.exe";
					p.StartInfo.Arguments = @"/c mspaint";
					p.StartInfo.UseShellExecute = false;
					p.StartInfo.RedirectStandardInput = true;
					p.StartInfo.RedirectStandardOutput = true;
					p.StartInfo.RedirectStandardError = true;
					p.StartInfo.CreateNoWindow = true;
					p.Start();
					break;
				}
			case "2":
				{
					System.Diagnostics.Process p = new System.Diagnostics.Process();
					p.StartInfo.FileName = "cmd.exe";
					p.StartInfo.Arguments = @"/c calc";
					p.StartInfo.UseShellExecute = false;
					p.StartInfo.RedirectStandardInput = true;
					p.StartInfo.RedirectStandardOutput = true;
					p.StartInfo.RedirectStandardError = true;
					p.StartInfo.CreateNoWindow = true;
					p.Start();
					break;
				}
			case "3":
				{
					System.Diagnostics.Process p = new System.Diagnostics.Process();
					p.StartInfo.FileName = "cmd.exe";
					p.StartInfo.Arguments = @"/c magnify";
					p.StartInfo.UseShellExecute = false;
					p.StartInfo.RedirectStandardInput = true;
					p.StartInfo.RedirectStandardOutput = true;
					p.StartInfo.RedirectStandardError = true;
					p.StartInfo.CreateNoWindow = true;
					p.Start();
					break;
				}
			case "4":
				{
					System.Diagnostics.Process p = new System.Diagnostics.Process();
					p.StartInfo.FileName = "cmd.exe";
					p.StartInfo.Arguments = @"/c appwiz.cpl";
					p.StartInfo.UseShellExecute = false;
					p.StartInfo.RedirectStandardInput = true;
					p.StartInfo.RedirectStandardOutput = true;
					p.StartInfo.RedirectStandardError = true;
					p.StartInfo.CreateNoWindow = true;
					p.Start();
					break;
				}
			case "5":
				{
					System.Diagnostics.Process p = new System.Diagnostics.Process();
					p.StartInfo.FileName = "cmd.exe";
					p.StartInfo.Arguments = @"/c ncpa.cpl";
					p.StartInfo.UseShellExecute = false;
					p.StartInfo.RedirectStandardInput = true;
					p.StartInfo.RedirectStandardOutput = true;
					p.StartInfo.RedirectStandardError = true;
					p.StartInfo.CreateNoWindow = true;
					p.Start();
					break;
				}
			case "6":
				{
					System.Diagnostics.Process p = new System.Diagnostics.Process();
					p.StartInfo.FileName = "cmd.exe";
					p.StartInfo.Arguments = @"/c odbcad32";
					p.StartInfo.UseShellExecute = false;
					p.StartInfo.RedirectStandardInput = true;
					p.StartInfo.RedirectStandardOutput = true;
					p.StartInfo.RedirectStandardError = true;
					p.StartInfo.CreateNoWindow = true;
					p.Start();
					break;
				}
			case "7":
				{
					System.Diagnostics.Process p = new System.Diagnostics.Process();
					p.StartInfo.FileName = "cmd.exe";
					p.StartInfo.Arguments = @"/c stikynot";
					p.StartInfo.UseShellExecute = false;
					p.StartInfo.RedirectStandardInput = true;
					p.StartInfo.RedirectStandardOutput = true;
					p.StartInfo.RedirectStandardError = true;
					p.StartInfo.CreateNoWindow = true;
					p.Start();
					break;
				}
			case "8":
				{
					System.Diagnostics.Process p = new System.Diagnostics.Process();
					p.StartInfo.FileName = "cmd.exe";
					p.StartInfo.Arguments = @"/c notepad";
					p.StartInfo.UseShellExecute = false;
					p.StartInfo.RedirectStandardInput = true;
					p.StartInfo.RedirectStandardOutput = true;
					p.StartInfo.RedirectStandardError = true;
					p.StartInfo.CreateNoWindow = true;
					p.Start();
					break;
				}
			case "9":
				{
					System.Diagnostics.Process p = new System.Diagnostics.Process();
					p.StartInfo.FileName = "cmd.exe";
					p.StartInfo.Arguments = @"/c compmgmtlauncher";
					p.StartInfo.UseShellExecute = false;
					p.StartInfo.RedirectStandardInput = true;
					p.StartInfo.RedirectStandardOutput = true;
					p.StartInfo.RedirectStandardError = true;
					p.StartInfo.CreateNoWindow = true;
					p.Start();
					break;
				}
			default:
				{
					Console.WriteLine("Unknown command '{0}' ignored.", command);
					break;
				}
		}
	}
}

執行畫面:

 owsConsole   

arrow
arrow
    文章標籤
    C# Console Win8 Command
    全站熱搜
    創作者介紹
    創作者 西夏普 的頭像
    西夏普

    西夏普的部落格

    西夏普 發表在 痞客邦 留言(0) 人氣()