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

如何获取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 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.

    点赞 评论 复制链接分享

相关推荐