#win32 #utils #filetime

win32_filetime_utils

Conversion utils from, and to Windows's FILETIME, SYSTEMTIME, etc

2 releases

Uses old Rust 2015

0.2.1 Jul 13, 2015
0.2.0 Jul 13, 2015

#3 in #kernel32

23 downloads per month
Used in win32_filetime_utils

Apache-2.0

15KB
337 lines

win32_filetime_utils

Conversion utils from, and to Windows's FILETIME, SYSTEMTIME, etc ...

Example

cargo.toml

...
[dependencies]
win32_filetime_utils = "0.2.0"

Convert from FILETIME, and print nicely formated process's creation time. main.rs

extern crate kernel32;
extern crate winapi;
extern crate win32_filetime_utils;

use std::ptr;
use self::kernel32::OpenProcess;
use self::winapi::HANDLE;
use win32_filetime_utils::*;

fn main()
{
    print_process_creation_time(7448); // => prints 2015-07-12 11:31:16
}

fn get_process_times(handle: HANDLE) -> Option<(i64, i64, i64, i64)>
{
    let ref mut a: i64 = 0;
    let ref mut b: i64 = 0;
    let ref mut c: i64 = 0;
    let ref mut d: i64 = 0;

    let r = unsafe { GetProcessTimes(handle, a as *mut i64, b as *mut i64, c as *mut i64, d as *mut i64) };
    if r <= 0 
    {
        None    
    }
    else 
    {

        Some((*a, *b, *c, *d))
    }
}

fn print_process_creation_time(pid: u32)
{
    let handle = unsafe { OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid) };
    if handle == ptr::null_mut() { return; }

    let (creation_time, _, _, _) = match get_process_times(handle)
    {
        Some(tup) => tup,
        _ => { return; }
    };
    let lst = ticks_to_local_systemtime(creation_time);
    let time = systemtime_to_naive_date_time(&lst);

    println!("{}", time);
}



const PROCESS_QUERY_LIMITED_INFORMATION: u32 = 0x1000;
extern "system"
{
    fn GetProcessTimes(
        handle: HANDLE
        , lpCreationTime: *mut i64
        , lpExitTime: *mut i64
        , lpKernelTime: *mut i64
        , lpUserTime: *mut i64
    ) -> i32;
}

Dependencies

~2.5MB
~37K SLoC