1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-26 13:48:59 +08:00
shirou_gopsutil/host_windows.go

67 lines
1.2 KiB
Go
Raw Normal View History

2014-04-18 21:28:00 +09:00
// +build windows
2014-04-22 09:44:22 +09:00
package gopsutil
2014-04-18 21:28:00 +09:00
import (
"os"
2014-04-18 22:02:35 +09:00
"syscall"
"unsafe"
)
var (
procGetSystemTimeAsFileTime = modkernel32.NewProc("GetSystemTimeAsFileTime")
procGetTickCount = modkernel32.NewProc("GetTickCount")
2014-04-18 21:28:00 +09:00
)
func HostInfo() (HostInfoStat, error) {
ret := HostInfoStat{}
2014-04-18 21:28:00 +09:00
hostname, err := os.Hostname()
if err != nil {
return ret, err
}
ret.Hostname = hostname
uptimemsec, _, err := procGetTickCount.Call()
if uptimemsec == 0 {
return ret, syscall.GetLastError()
2014-04-18 22:02:35 +09:00
}
ret.Uptime = int64(uptimemsec) / 1000
2014-04-19 01:05:35 +09:00
2014-04-30 17:15:28 +09:00
procs, err := Pids()
2014-04-19 01:05:35 +09:00
if err != nil {
return ret, err
}
ret.Procs = uint64(len(procs))
2014-04-18 21:28:00 +09:00
return ret, nil
}
2014-04-22 21:39:18 +09:00
2014-04-30 15:32:05 +09:00
func BootTime() (int64, error) {
var lpSystemTimeAsFileTime FILETIME
r, _, _ := procGetSystemTimeAsFileTime.Call(uintptr(unsafe.Pointer(&lpSystemTimeAsFileTime)))
if r == 0 {
return 0, syscall.GetLastError()
}
// TODO: This calc is wrong.
ll := (uint32(lpSystemTimeAsFileTime.DwHighDateTime))<<32 + lpSystemTimeAsFileTime.DwLowDateTime
pt := (uint64(ll) - 116444736000000000) / 10000000
u, _, _ := procGetTickCount.Call()
if u == 0 {
return 0, syscall.GetLastError()
}
uptime := uint64(u) / 1000
2014-04-22 21:39:18 +09:00
return int64(pt - uptime), nil
2014-04-22 21:39:18 +09:00
}
func Users() ([]UserStat, error) {
2014-04-30 15:32:05 +09:00
var ret []UserStat
2014-04-22 21:39:18 +09:00
return ret, nil
}