最近用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;
}