Command netsh using C#

前端 未结 1 499
梦如初夏
梦如初夏 2021-01-16 23:53

I want to create a C# application to create a WLAN network. I currently use netsh using command prompt. My application should do this in button click. Here is the command I

相关标签:
1条回答
  • 2021-01-17 00:21

    You shouldn't do this: +"netsh wlan start hostednetwork" to the arguments of the first process. That would mean that you are typing this at the console:

    netsh wlan set hostednetwork mode=allow ssid=sha key=12345678netsh wlan start hostednetwork
    

    Instead, make a new process for the second line:

    private void button1_Click(object sender, EventArgs e)
    {
         Process p1 = new Process();
         p1.StartInfo.FileName = "netsh.exe";
         p1.StartInfo.Arguments = "wlan set hostednetwork mode=allow ssid=sha key=12345678";            
         p1.StartInfo.UseShellExecute = false;
         p1.StartInfo.RedirectStandardOutput = true;
         p1.Start();
    
         Process p2 = new Process();
         p2.StartInfo.FileName = "netsh.exe";
         p2.StartInfo.Arguments = "wlan start hostednetwork";            
         p2.StartInfo.UseShellExecute = false;
         p2.StartInfo.RedirectStandardOutput = true;
         p2.Start();
    }
    
    0 讨论(0)
提交回复
热议问题