[C #] Winform tool-quick Wifi sharing (Source Code) in the flash drive ),
A. Introduction to tools
I have been busy changing my thesis recently. 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 of "command prompt:
And some. NET systems are managed:
Tested, this tool does not affect the heartbeat verification of the Flash message, and the Internet access is stable. It does not disconnect the network in a few minutes as it is 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.
Github source code (project file ):Https://github.com/Blz-Galaxy/Tools-Wifi-Sharing
B. Instructions and execution
Related command prompt (you can also use the BAT script)
Here, the hotspot ID is Blz_Galaxy and the password is 1234567890. Please modify it by yourself.
- Timed Shutdown(Shutdown after 3600 seconds ):
shutdown -s -t 3600
- It can also be set after ShutdownCancel shutdown plan:
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. Perform system management through C # (. NET)
- Automatically shut down the specified process (such as the "singleNet" Process of the flash)
Replaced manual search for processes in the task manager to save intensive phobias ~
For details, see:[C #] specify that the process is disabled and Wifi sharing under flash
- 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 ~