Skip to content

Instantly share code, notes, and snippets.

@Iristyle
Created September 8, 2016 21:08
Show Gist options
  • Select an option

  • Save Iristyle/a6cb43d3d6d9f3756b29ef1706120e8b to your computer and use it in GitHub Desktop.

Select an option

Save Iristyle/a6cb43d3d6d9f3756b29ef1706120e8b to your computer and use it in GitHub Desktop.
Windows API GetTickCount64 used to retrieve system uptime on Windows with 64-bit resolution (5000+ years)
$signature = @'
[DllImport(@"kernel32.dll", SetLastError=true)]
public static extern UInt64 GetTickCount64 ();
'@
$type = Add-Type -MemberDefinition $signature -Name SystemTime -Namespace GetTickCount64 -PassThru
[System.TimeSpan]::FromMilliseconds($type::GetTickCount64())
@Iristyle
Copy link
Copy Markdown
Author

Iristyle commented Sep 8, 2016

This API exists on Vista+ - no 32-bit vs 64-bit issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment