What is the best way to get windows full name from go? -
in windows, can run systeminfo | findstr /c:"os name
output windows full name console. i've tried couple different variations of piping output 1 command other, empty strings.
example
first := exec.command("systeminfo") second := exec.command("findstr /c:'os name'") reader, writer := io.pipe() first.stdout = writer second.stdin = reader var buffer bytes.buffer second.stdout = &buffer first.start() second.start() first.wait() writer.close() second.wait() output := buffer.string() log.printf("output: %s", output)
`
are there built in methods information?
one way use golang.org/x/sys/windows/registry package.
a simple example:
package main import ( "fmt" "golang.org/x/sys/windows/registry" ) func main() { key, _ := registry.openkey(registry.local_machine, `software\microsoft\windows nt\currentversion`, registry.query_value) // error discarded brevity defer key.close() productname, _, _ := key.getstringvalue("productname") // error discarded brevity fmt.println(productname) }
this prints windows 8.1 pro
on computer.
Comments
Post a Comment