110,534
社区成员
发帖
与我相关
我的任务
分享
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private static string CMD(string command)
{
Process process = new Process();//创建进程对象
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";//设定需要执行的命令
startInfo.Arguments = "/C " + command;//“/C”表示执行完命令后马上退出
startInfo.UseShellExecute = false;//不使用系统外壳程序启动
startInfo.RedirectStandardInput = false;//不重定向输入
startInfo.RedirectStandardOutput = true; //重定向输出
startInfo.CreateNoWindow = true;//不创建窗口
process.StartInfo = startInfo;
process.Start();//开始进程
process.WaitForExit();//等待进程结束
string result = process.StandardOutput.ReadToEnd();//读取进程的输出
process.Close();
return result;
}
private void button1_Click(object sender, EventArgs e)
{
Console.WriteLine(CMD("netsh wlan set hostednetwork mode=allow ssid=lin key=12345678"));
Console.WriteLine(CMD("netsh wlan start hostednetwork"));
}
private void button2_Click(object sender, EventArgs e)
{
Console.WriteLine(CMD("netsh wlan stop hostednetwork"));
}
}
}