在Golang中,你可以使用exec.Command函数来执行命令行命令,并通过管道获取输出结果。具体来说,你可以使用以下代码来获取Windows系统上已安装的软件列表:

package main

import (
	"fmt"
	"os/exec"
	"strings"
)

func main() {
	cmd := exec.Command("wmic", "product", "get", "name")
	output, err := cmd.Output()
	if err != nil {
		fmt.Println("Failed to get software list:", err)
		return
	}

	softwareList := string(output)
	softwareList = strings.ReplaceAll(softwareList, "\r\r\n", "\n")
	lines := strings.Split(softwareList, "\n")

	for _, line := range lines {
		if line != "Name" && line != "" {
			fmt.Println(line)
		}
	}
}

这段代码使用wmic命令来获取已安装软件的名称列表。wmic是Windows Management Instrumentation Command-line(WMI)的命令行界面工具,用于获取系统信息。我们使用wmic product get name命令来获取已安装软件的名称。

注意,你需要在Windows系统上安装并配置好wmic命令行工具,以便在命令行中使用它

golang获取windows 系统安装的软件列表

原文地址: https://www.cveoy.top/t/topic/ieRq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录