-4

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?

kostix
  • 51,517
  • 14
  • 93
  • 176
Jack Smith
  • 23
  • 3

1 Answers1

3

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.

kostix
  • 51,517
  • 14
  • 93
  • 176
  • That detour is brilliant! – RickyA Nov 15 '17 at 13:20
  • Спасибо вам большое. Но я одного не могу понять и не могу найти: Как мне сменить запрос допустим на bios, пробовал Win32_Bios но пишет Invalid Class или Invalid Query. Информацию как сменить запрос не нашел. – Jack Smith Nov 15 '17 at 16:42
  • @JackSmith, sorry I don't even have access to Windows and was writing off my memory. [This](https://social.technet.microsoft.com/Forums/en-US/c5684592-adaf-4fcd-8adb-335c7633ca71/query-bios-version-before-running-command-or-installing-application?forum=mdt) has a working WMI query for bios: `select * from WIN32_BIOS where SMBIOSBIOSVersion < "A26"` so I'd work from there. See also [this](https://msdn.microsoft.com/en-us/library/Aa394077.aspx). – kostix Nov 15 '17 at 17:05
  • @JackSmith …and [this](https://www.google.ru/search?q=WMI+BIOS+site%3Arsdn.ru) and the links provided [here](https://habrahabr.ru/post/138400/#comment_4622655) and so on. Please do your research. – kostix Nov 15 '17 at 17:07
  • @kostix this is most importand for me i was able to find it - https://msdn.microsoft.com/en-us/library/aa389273%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 – Jack Smith Nov 15 '17 at 18:51