Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I accidentally discovered that in Windows 8, if you right-click a previously connected wireless network from the Start screen interface, there's an option to show estimated data usage.

enter image description here

enter image description here

Where's this data stored? Is it possible to fetch this via PowerShell/WMI? A use case for me would be to setup automated alerts based on data usage - I currently use Networx for a more detailed breakdown, but for a quick alert, if I can fetch the usage, the automated route would help a lot.

share|improve this question
1  
I wonder why it's only estimated. –  Oliver Salzburg Jan 10 '13 at 14:23
    
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Network\DataUsage\W‌​lan looks related. I'm still searching. –  Bob Jan 10 '13 at 15:31
    
It is related, but my research shows it's purely gui related, haven't seen anything on where the actual estimate is stored. nothing on google for that reg key except one result at this time. –  BigHomie Jan 12 '13 at 21:20
1  
@OliverSalzburg Probably they call it estimated because it may show a different number than your ISP. Possibly they're guessing at some percent overhead as well (which Windows can't measure, as its being added elsewhere) –  derobert Jan 16 '13 at 18:08

2 Answers 2

I remember when you first asked this question, but I finally got around to figuring it out. Hope it's still of use to you or someone else!

You can access the this data by calling the GetLocalUsage method of ConnectionProfile objects, which are WLAN/WAN connections (i.e. SSIDs). GetLocalUsage takes two DateTime parameters and returns a DataUsage object containing the amount of data sent and received during the interval specified. You can get a list of ConnectionProfile objects by calling the GetConnectionProfiles method of NetworkInformation.

I wrote the following function that retrieves the data and returns an object. Pass to it one or more SSIDs and optionally start and stop DateTime's:

function Get-EstimatedDataUsage()
{
    Param(
        [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$ProfileName,

        [Parameter(Position=1, Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [DateTime]$From,

        [Parameter(Position=2, Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [DateTime]$To
    )

    Process
    {
        foreach($profile in $ProfileName)
        {
            try
            {
                [void][Windows.Networking.Connectivity.NetworkInformation,Windows,ContentType=WindowsRuntime]
                $ConnectionProfiles = [Windows.Networking.Connectivity.NetworkInformation]::GetConnectionProfiles() | Where-Object ProfileName -EQ $profile
            }
            catch
            {
                Write-Error 'Unable to create instance of Windows.Networking.Connectivity.NetworkInformation.'
                continue
            }

            foreach($ConnectionProfile in $ConnectionProfiles)
            {
                $ProfileName = $ConnectionProfile.ProfileName

                if($From -eq $null)
                {
                    try
                    {
                        $ResetTime = Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Network\DataUsage\Wlan\$ProfileName -Name ResetTime -ErrorAction Stop | Select-Object -ExpandProperty ResetTime
                        $From_determined = [datetime]::FromFileTime($ResetTime)
                    }
                    catch
                    {
                        $From_determined = [datetime]::FromFileTime(0)
                    }
                }
                else
                {
                    $From_determined = $From
                }

                if($To -eq $null)
                {
                    $To_determined = Get-Date
                }
                else
                {
                    $To_determined = $To
                }

                $usage = $ConnectionProfile.GetLocalUsage($From_determined, $To_determined)

                $op = '' | select Name,Received,Sent,From,To

                $op.Name = $ProfileName
                $op.Received = $usage.BytesReceived
                $op.Sent = $usage.BytesSent
                $op.From = $From_determined
                $op.To = $To_determined

                $op

            }
        }
    }
}
share|improve this answer
    
Great, thanks for the research and the answer! –  Sathya Jul 7 at 4:44

This MSDN article is the best I could find from Microsoft: http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.datausage.aspx. It tells you how you can call it from a program, but not where the data proper is stored. I'm not going to copy and paste it all because I don't know which language you prefer to program in.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.