我们计划在Visual Studio中使用XAML和C#开发一个wifi热点应用程序。我们无法找到任何类或方法来从桌面访问命令提示符。我们需要在Windows 8中使用Internet共享键入以下代码以启动热点连接: netsh wlan设置hostednetwork mode = allow ssid = ConnectionName key = 8Characters 我们需要以某种方式解决这个问题,通过它我们可以将上述命令发送到命令提示符并使用Windows 8应用程序启动连接。 请帮我。 谢谢。
答案 0 :(得分:1)
使用System.Diagnostics.Process执行命令。
示例代码,几乎逐字逐句复制,根据您的需要进行修改:
using System;
using System.Diagnostics;
using System.ComponentModel;
namespace MyProcessSample
{
class MyProcess
{
public static void Main()
{
Process myProcess = new Process();
try
{
myProcess.StartInfo.UseShellExecute = false;
// You can start any process, HelloWorld is a do-nothing example.
myProcess.StartInfo.FileName = "%Windir%\System32\netsh.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.Arguments = "wlan set hostednetwork mode=allow ssid=ConnectionName key=8Characters ";
myProcess.Start();
// This code assumes the process you are starting will terminate itself.
// Given that is is started without a window so you cannot terminate it
// on the desktop, it must terminate itself or you can do it programmatically
// from this application using the Kill method.
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
答案 1 :(得分:0)
您可以创建批处理文件,让程序在启动时运行该文件。
something.bat with
netsh wlan set hostednetwork mode=allow ssid=ConnectionName key=8Characters