針對校園網閃訊撥號環境,整合 Windows 原生功能,避免獵豹/360 WiFi 等第三方工具導致系統假死。主要功能:
hnetcfg.dll 實現網路連線自動共享 (免手動設定)實測不影響閃訊心跳驗證,上網穩定,不會像手動共享幾分鐘後斷網。
netsh wlan set hostednetwork mode=allow ssid=YourSSID key=YourPasswordnetsh wlan start hostednetworknetsh wlan stop hostednetworkshutdown -s -t 3600shutdown -aProcess _pCmd = new Process();
_pCmd.StartInfo.FileName = "cmd.exe";
_pCmd.StartInfo.UseShellExecute = false;
_pCmd.StartInfo.RedirectStandardInput = true;
_pCmd.StartInfo.RedirectStandardOutput = true;
_pCmd.StartInfo.CreateNoWindow = true;
_pCmd.Start();
_pCmd.StandardInput.WriteLine("shutdown -a"); // 範例:取消關機
Regex reg = new Regex(@"[\u4e00-\u9fa5]");
if (reg.IsMatch(txtSSID.Text) || reg.IsMatch(txtPwd.Text)) {
MessageBox.Show("不能含有漢字"); return;
}
Process[] processes = Process.GetProcessesByName("singleNet");
foreach (Process p in processes) {
try { if (p.ProcessName == "singleNet") p.Kill(); } catch { }
}
hnetcfg.dll (COM: NETCONLib) 實現自動 ICS 共享try {
string connToShare = txtShareFrom.Text; // 已連網的介面 (如 singleNet PPPoE)
string connSharedFor = txtShareTo.Text; // 虛擬 WiFi 介面
NetSharingManager manager = new NetSharingManager();
foreach (INetConnection c in manager.EnumEveryConnection) {
var props = manager.NetConnectionProps[c];
var cfg = manager.INetSharingConfigurationForINetConnection[c];
if (props.Name == connToShare)
cfg.EnableSharing(tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PUBLIC);
else if (props.Name == connSharedFor)
cfg.EnableSharing(tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PRIVATE);
}
} catch {
MessageBox.Show("請確認已連接網際網路並開啟網路共享中心");
}
此段程式碼替代了手動進入「網路共享中心 → 更改介面卡設定 → 屬性 → 共享 → 勾選允許分享 → 選擇目標介面」的繁瑣操作。