private void MainDialog_Load(object sender, EventArgs e) { //CheckForIllegalCrossThreadCalls = False if (!(System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\netsh.exe"))) { MessageBox.Show("netsh.exe Not found!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } else { AppTray.Visible = true; StartUpRegistryCheck(); if (startButton.Text == "&Start") { IcsRefreshThread.RunWorkerAsync(); } } }
private void refreshConnectionButton_Click(object sender, EventArgs e) { IcsRefreshThread.RunWorkerAsync(); }
private void DisconnectFunction() { startButton.Enabled = false; StatusLbl.Text = "Status: Trying to stop hotspot!"; TrayStoppingStatus(); IcsManager.ShareConnection(null, null); //Dim SysPath As String //SysPath = Environment.GetFolderPath(Environment.SpecialFolder.System) //Dim CommandSeperator As String //CommandSeperator = "&&" if (System.IO.File.Exists(SysPath + "\\netsh.exe")) { var ConnectionProcess = new Process(); ConnectionProcess.StartInfo.FileName = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\cmd.exe"; ConnectionProcess.StartInfo.Arguments = "/k echo off" + CommandSeperator + SysPath + "\\netsh.exe wlan stop hostednetwork"; ConnectionProcess.StartInfo.UseShellExecute = false; ConnectionProcess.StartInfo.CreateNoWindow = true; ConnectionProcess.StartInfo.RedirectStandardOutput = true; ConnectionProcess.StartInfo.RedirectStandardError = true; ConnectionProcess.Start(); ConnectionProcess.WaitForExit(4000); if (!ConnectionProcess.HasExited) { ConnectionProcess.Kill(); System.IO.StreamReader SuccessOutPut = ConnectionProcess.StandardOutput; System.IO.StreamReader ErrorOutPut = ConnectionProcess.StandardError; string ProcessSuccess = null; string ProcessError = null; ProcessSuccess = SuccessOutPut.ReadToEnd(); ProcessError = ErrorOutPut.ReadToEnd(); if (string.IsNullOrEmpty(ProcessError)) { if (ProcessSuccess.Contains("The hosted network stopped")) { StatusLbl.Text = "Status: Hotspot stopped!"; EnableUserInterface(); IcsRefreshThread.RunWorkerAsync(); startButton.Text = "&Start"; startButton.Enabled = true; TrayStoppedStatus(); } } else { EnableUserInterface(); MessageBox.Show(ProcessError, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } SuccessOutPut.Close(); ErrorOutPut.Close(); ConnectionProcess.Close(); } } else { MessageBox.Show("netsh.exe Not found!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }