[C #] Winform tool-quick Wifi sharing under flash (source code)
A. tool introduction recently, I have been busy changing my papers. However, due to the lack of mobile phone traffic, I have been unable to bear the trouble of repeatedly Sharing Computer wifi, however, tools such as "Cheetah wifi" and "360wifi sharing" have caused the computer to sleep for many times (possibly due to the compatibility problem of the desktop USB Nic ). Therefore, I took the time to write a convenient tool, which was fully implemented using the built-in functions of windows. I combined several commands for "command prompt": set the built-in wifi hotspot for windows; Enable and disable wifi; automatic shutdown and cancellation (mainly because I like playing on the bed before going to bed, and I am too lazy to get up and shut down my computer) and some. NET to manage the system: Disable the flash process (to avoid the flash lock sharing function); Use the built-in windows library for automatic sharing, avoid manual settings. (Many people may be stuck in this step) after testing, this tool does not affect heartbeat verification, and the Internet access is stable, and the network will not be disconnected in a few minutes as if it were shared manually. Of course, if you are not a campus network user in the Zhejiang region, you may not need to dial for such information as flash messages. You just need to open a hotspot for sharing. M [AVEDG @) 2 W %] ZD $ IJ4FQOO B. command and execution related command prompt (can also be called using BAT script) to set the system's built-in Virtual network Adapter Microsoft Virtual WiFi Miniport Adapter, so as to create a hotspot (only need to configure before the first use ): netsh wlan set hostednetwork mode = allow ssid = Blz_Galaxy key = 1234567890 the hotspot ID here is Blz_Galaxy and the password is 1234567890. Please modify it by yourself. Enable shared Wifi hotspot: netsh wlan start hostednetwork disable Wifi hotspot: netsh wlan stop hostednetwork Timed Shutdown (shutdown after 3600 seconds ): shutdown-s-t 3600 you can also cancel the shutdown plan after setting shutdown: shutdown-a C # Call the console command method:
System.Diagnostics.Process _pCmd;_pCmd = new System.Diagnostics.Process();_pCmd.StartInfo.FileName = "cmd.exe";_pCmd.StartInfo.UseShellExecute = false;_pCmd.StartInfo.RedirectStandardOutput = true;_pCmd.StartInfo.RedirectStandardInput = true;_pCmd.StartInfo.CreateNoWindow = true;_pCmd.Start();
// Execute the target command _ pCmd. StandardInput. WriteLine ("shutdown-a"); another example:
Regex reg = new Regex (@ "[\ u4e00-\ u9fa5]"); // Regular Expression if (reg. isMatch (textBox1.Text) | reg. isMatch (textBox2.Text) {MessageBox. show ("cannot contain Chinese characters"); return;} if (textBox2.Text. length <8) {MessageBox. show ("more than 8 passwords"); return;} _ strWrite = String. format ("netsh wlan set hostednetwork mode = allow ssid = {0} key = {1}", this. textBox1.Text, this. textBox2.Text); _ pCmd. standardInput. writeLine (_ strWrite );
C. Using C # (. NET) for system management, automatic shutdown of the specified process (such as the "singleNet" Process of Flash) replaces manual process searching in the task manager to save intensive phobias ~
Process[] processes = Process.GetProcessesByName(ProcessName);foreach (Process instance in processes){ try { if (instance.ProcessName == ProcessName) instance.Kill();; } catch { }
By calling \ Windows \ system32 \ hnetcfg. dll, "NETCONLib" can be used for automatic sharing (key)
Try {string connectionToShare = this. textBox3.Text; // The shared network connection string sharedForConnection = this. textBox4.Text; // network connection to be shared NetSharingManager = new NetSharingManager (); var connections = manager. enumEveryConnection; foreach (INetConnection c in connections) {var props = manager. netConnectionProps [c]; var sharingCfg = manager. INetSharingConfigurationForINetConnection [c]; if (props. name = ConnectionToShare) {sharingCfg. enableSharing (tagSHARINGCONNECTIONTYPE. ICSSHARINGTYPE_PUBLIC);} else if (props. name = sharedForConnection) {sharingCfg. enableSharing (tagSHARINGCONNECTIONTYPE. ICSSHARINGTYPE_PRIVATE) ;}} catch {MessageBox. show ("Open the network and sharing center. Check if the network is connected to the Internet! "," Prompt ", MessageBoxButtons. OK, MessageBoxIcon. Information );}
Choose "Network Sharing Center"> "Change adapter Settings"> "singleNetPPPoE properties"> "share"> "allow internet sharing"> "select" sharing target ~