#filetime #system-time #convert #winapi #windows

win32_filetime_utils

Windows的FILETIME,SYSTEMTIME等之间的转换工具

2 个版本

使用旧的 Rust 2015

0.2.1 2015年7月13日
0.2.0 2015年7月13日

#8 in #filetime


用于 win32_filetime_utils

Apache-2.0

15KB
337

win32_filetime_utils

Windows的FILETIME,SYSTEMTIME等之间的转换工具...

示例

cargo.toml

...
[dependencies]
win32_filetime_utils = "0.2.0"

从FILETIME转换,并打印格式化良好的进程创建时间。 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;
}

依赖项

~2.5MB
~37K SLoC