Click here to Skip to main content
12,078,795 members (50,862 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

10.2K views
283 downloads
16 bookmarked
Posted

Wi-Fi Timer

, 25 Nov 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Schedule your wifi status

Introduction

In many situations, I needed to control wi-fi status on my PC. Tuning on/off automatically [midnight > morning] well, because my ISP doesn't invoice on traffic in that interval, and some programs need/use large amount of data..

Background

This is an easy way is to use command prompt cmd.exe.

netsh.exe does the job. [under administrator privileges]*

Enable Interface: netsh interface set interface "interfaceName" enable

Disable Interface: netsh interface set interface "interfaceName" disable

Using the Code

In brief, running this command in C#. By starting netsh.exe process with the above explained arguments:

private enum Status
{
    Online,
    Offline
}
 
private static void SetStatus(string interfaceName, Status status)
{
    string state = status == Status.Online ? "enable" : "disable";
 
    string arguments = "interface set interface \"{0}\" {1}";
 
    string args = string.Format(arguments, interfaceName, state);
 
    var NetshStartInfo = new System.Diagnostics.ProcessStartInfo("netsh", args)
    {
        CreateNoWindow = true,
        RedirectStandardOutput = true,
        UseShellExecute = false,
        WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
    };
 
    var Netsh = new System.Diagnostics.Process
    {
        StartInfo = NetshStartInfo
    };
 
    Netsh.Start();
}

The source code includes usage of the application settings to load/save options, Linq expressions, and some WPF styling...

* to run with administrator permission, add to the app.manifest file in solution explorer these line of code into:

<asmv1:assembly ...>  
<.../>      
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel level="highestAvailable" uiAccess="false" />
      </requestedPrivileges>
    </security> 
</trustInfo>
</asmv1:assembly>  

Points of Interest

It's a light way. Usage is up to certain limits and conditions. Advanced solution can be by scheduling firewall rules on certain programs. And starting them with arguments, etc.

Thanks! Big Grin | <img src=

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

F. ARO
Engineer
Lebanon Lebanon
Electronics, Telecommunications, Development, Music!

You may also be interested in...

Comments and Discussions

 
BugStay where it was... Pin
Peter Leow22-Apr-14 2:45
professionalPeter Leow22-Apr-14 2:45 
GeneralRe: Stay where it was... Pin
OriginalGriff22-Apr-14 2:59
protectorOriginalGriff22-Apr-14 2:59 
GeneralMy vote of 5 Pin
johannesnestler25-Nov-13 5:35
memberjohannesnestler25-Nov-13 5:35 
GeneralRe: My vote of 5 Pin
F. ARO25-Nov-13 9:35
memberF. ARO25-Nov-13 9:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.160212.1 | Last Updated 25 Nov 2013
Article Copyright 2013 by F. ARO
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid