|
|
|
// +build windows
|
|
|
|
|
|
|
|
package staros
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"b612.me/wincmd"
|
|
|
|
|
|
|
|
"b612.me/win32api"
|
|
|
|
)
|
|
|
|
|
|
|
|
// StartTime 开机时间
|
|
|
|
func StartTime() time.Time {
|
|
|
|
data, _ := win32api.GetTickCount()
|
|
|
|
date := float64(time.Now().Unix())
|
|
|
|
unix := date - float64(data)/1000
|
|
|
|
max := (unix - float64(int64(unix))) * 1000000000
|
|
|
|
return time.Unix(int64(unix), int64(max))
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsRoot 当前是否是管理员用户
|
|
|
|
func IsRoot() bool {
|
|
|
|
return wincmd.Isas()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Memory 系统内存信息
|
|
|
|
func Memory() MemStatus {
|
|
|
|
var mem MemStatus
|
|
|
|
ram := new(win32api.MEMORYSTATUSEX)
|
|
|
|
win32api.GlobalMemoryStatusEx(ram)
|
|
|
|
mem.All = uint64(ram.UllTotalPhys)
|
|
|
|
mem.Free = uint64(ram.UllAvailPhys)
|
|
|
|
mem.Available = uint64(ram.UllAvailPhys)
|
|
|
|
mem.Used = uint64(mem.All - mem.Free)
|
|
|
|
mem.SwapAll = uint64(ram.UllTotalPageFile)
|
|
|
|
mem.SwapFree = uint64(ram.UllAvailPageFile)
|
|
|
|
mem.SwapUsed = mem.SwapAll - mem.SwapFree
|
|
|
|
mem.VirtualAll = uint64(mem.VirtualAll)
|
|
|
|
mem.VirtualAvail = uint64(mem.VirtualAvail)
|
|
|
|
mem.VirtualUsed = mem.VirtualAll - mem.VirtualUsed
|
|
|
|
return mem
|
|
|
|
}
|
|
|
|
|
|
|
|
func DiskUsage(path string) (disk DiskStatus) {
|
|
|
|
kernel32, err := syscall.LoadLibrary("Kernel32.dll")
|
|
|
|
if err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
|
|
|
defer syscall.FreeLibrary(kernel32)
|
|
|
|
GetDiskFreeSpaceEx, err := syscall.GetProcAddress(syscall.Handle(kernel32), "GetDiskFreeSpaceExW")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
lpFreeBytesAvailable := int64(0)
|
|
|
|
lpTotalNumberOfBytes := int64(0)
|
|
|
|
lpTotalNumberOfFreeBytes := int64(0)
|
|
|
|
syscall.Syscall6(uintptr(GetDiskFreeSpaceEx), 4,
|
|
|
|
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("C:"))),
|
|
|
|
uintptr(unsafe.Pointer(&lpFreeBytesAvailable)),
|
|
|
|
uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)),
|
|
|
|
uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes)), 0, 0)
|
|
|
|
disk.Free = uint64(lpTotalNumberOfFreeBytes)
|
|
|
|
disk.Used = uint64(lpTotalNumberOfBytes - lpTotalNumberOfFreeBytes)
|
|
|
|
disk.All = uint64(lpTotalNumberOfBytes)
|
|
|
|
disk.Available = uint64(lpFreeBytesAvailable)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func CpuUsage(sleep time.Duration) float64 {
|
|
|
|
return 0
|
|
|
|
}
|