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 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题