最近用unity做了個wifi熱點工具,總結下指令.
netsh wlan set hostednetwork mode=allow ssid=WIFINAME key=123456789
部署wifi模塊名稱與密碼並啓動服務
netsh wlan set hostednetwork mode=disallow
關閉部署的wifi服務
netsh wlan start hostednetwork
啓動wifi熱點
netsh wlan stop hostednetwork
關閉wifi熱點
netsh wlan show hostednetwork
檢測已連接設備
由於是在Unity中調用,附上執行cmd函數.
/// <summary>
/// 執行系統命令
/// </summary>
/// <param name="Command"></param>
/// <returns></returns>
public string ExecuteCmd(string Command)
{
string system32dir = System.Environment.GetEnvironmentVariable("windir") + "\\system32";
Process process = new Process
{
StartInfo = { FileName = string.Format("{0}\\{1}", system32dir, "cmd.exe"), Arguments = @"C:\Windows\System32\cmd.exe", UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, Verb = "RunAs", CreateNoWindow = true }
};
process.Start();
process.StandardInput.WriteLine(@"c:"); //先轉到系統盤下
process.StandardInput.WriteLine(@"cd C:\WINDOWS\system32\"); //再轉到CMD所在目錄下
process.StandardInput.WriteLine("chcp 65001");
//process.StandardInput.WriteLine(@"start cmd.exe ");
process.StandardInput.WriteLine(Command);
process.StandardInput.WriteLine("exit");
process.WaitForExit();
string str = process.StandardOutput.ReadToEnd();
process.Close();
return str;
}