dsaeyrq451928 2017-11-14 20:28
浏览 463

如何获取Windows的所有系统/ BIOS信息

I want to know how to get full information about PC and BIOS. I came across this post - https://groups.google.com/forum/#!msg/golang-nuts/pKuFQxAy4P4/62FnqGON1pEJ

Code:

package main

import (
    "fmt"
    "github.com/ochapman/godmi"
)
func main(){
    BS:=godmi.GetBIOSInformation()
    fmt.Println("BS:",BS)
    sys:=godmi.GetSystemInformation()
    fmt.Println("sys:",sys)
    BB:=godmi.GetBaseboardInformation()
    fmt.Println("BB:",BB)
}

I could not compile because there is an error:

# github.com/ochapman/godmi
go\src\github.com\ochapman\godmi\godmi.go:674:13: undefined: syscall.Mmap
go\src\github.com\ochapman\godmi\godmi.go:674:79: undefined: syscall.PROT_RE
go\src\github.com\ochapman\godmi\godmi.go:674:98: undefined: syscall.MAP_SHA
go\src\github.com\ochapman\godmi\godmi.go:680:8: undefined: syscall.Munmap

As I understood it only for Linux, for Windows I did not find anything like it at all. Can eat an alternative?

  • 写回答

1条回答 默认 最新

  • douling8087 2017-11-15 08:07
    关注

    A detour about the methodology in programming

    (Sorry for a detour, which follows, but I think I had to make it.)

    You're attacking your problem from a wrong angle. Programming is not about finding a random package, trying it, seeing it failing and turning for help; it's rather about inventing a general approach to solving the problem at hand and then trying to figure out what are there to solve it.

    For instance, in your case, it might easily be not fruitful to search for "BIOS+information+golang" because it's too narrow.

    Instead, try to figure out

    1. How to get any information about a system on Windows.
    2. How to do that in Go.

    While this is boring, I have to recommend reading this seriously: this will really help you getting your future programming challenges solved.

    The problem at hand

    OK, now back to your problem.

    On Windows, the standard way to obtain information about a system is querying the so-called Windows Management Instrumentation (or WMI for short) subsystem.

    Once you know this, you should dig into these two directions:

    • What WMI calls do you need to perform to get the information which is of interest to you.

      This one is easily searcheable. The first hit I got doing that is this which I'd say is a pretty good start.

    • How to do WMI calls from Go.

      This one can be done in two ways:

      • Direct implementation by hand. Go has very good built-in support for dynamically loading Windows DLLs and calling functions from them.

        This is a good demonstation of the basic concepts.

      • Using a ready-made package. Again, quick searching yields github.com/StackExchange/wmi.

    So, if I were you, I'd first code up whatever the WMI calls suit my needs using VBS or JScript (or whatnot) on WSH and then "ported" that solution to Go using any of the described approaches.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog