Go – how can i detect if the users PC is running some prerequisite tools such as Google Chrome for example

huangapple go评论81阅读模式
英文:

Go - how can i detect if the users PC is running some prerequisite tools such as Google Chrome for example

问题

如何通过Go执行我的应用程序来确保1和2返回true或false?

1)操作系统Windows XP、Vista、7、8,32/64位,如果该计算机已经安装了Google Chrome浏览器,返回true;否则返回false。

2)操作系统Mac/Apple,如果安装了Google Chrome浏览器,返回Yes;否则返回No。

package main
import "os/exec"
import "runtime"
import "fmt"
import "net/http"

const url = "http://localhsot:9090"

func main() {  
  myos := runtime.GOOS // linux, freebsd, netbsd, openbsd, plan9, darwin, windows
  fmt.Println(runtime.GOARCH) // 386, amd64, arm
  
  if myos == "windows" {
    if myarch == "386" {
      chrome := "C:/Program Files/Google/Chrome/Application/chrome.exe"
    } else {
      chrome := "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
    }          
    cmd := exec.Command(chrome, "--chrome-frame", url)
    err := cmd.Start()
    if err != nil {
      println("Failed to start chrome:", err)
    } 

  } else if myos == "darwin" {
    if myarch == "386" {
      cmd := exec.Command("open", "-b" , "com.google.Chrome", "--args", "--chrome-frame", url)
    } else {
      cmd := exec.Command("open", "-b" , "com.google.Chrome", "--args", "--chrome-frame", url)
    }
    err := cmd.Start()
    if err != nil {
      fmt.Println("failed")
    } 
    
  } else {
    if myarch == "386" {
      chrome := "google-chrome"
    } else {
      chrome := "google-chrome"
    }   
    
    cmd := exec.Command(chrome, "--chrome-frame", url)
    err := cmd.Start()
    if err != nil {
      fmt.Println("failed")
    }
    
  }

}
英文:

How can i be 100% sure and check with Go execution of my application that 1, 2 gives me true or false

  1. Operating system Windows XP, Vista, 7, 8, 32/64-bit OK
    if that PC already have Google Chrome browser installed or not?

  2. Operating system Mac/Apple, does it has Google Chrome browser Yes or not?

    package main
    import "os/exec"
    import "runtime"
    import "fmt"
    import "net/http"
    const url = "http://localhsot:9090"

    func main() {
    myos := runtime.GOOS // linux, freebsd, netbsd, openbsd, plan9, darwin, windows
    fmt.Println (runtime.GOARCH) // 386, amd64, arm

    if myos == "windows" {
    if myarch == "386" {
    chrome := "C:/Program Files/Google/Chrome/Application/chrome.exe"
    } else {
    chrome := "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
    }
    cmd := exec.Command(chrome, "--chrome-frame", url)
    err := cmd.Start()
    if err != nil {
    println("Failed to start chrome:", err)
    }

    } else if myos == "darwin" {
    if myarch == "386" {
    cmd := exec.Command("open", "-b" , "com.google.Chrome", "--args", "--chrome-frame", url)
    } else {
    cmd := exec.Command("open", "-b" , "com.google.Chrome", "--args", "--chrome-frame", url)
    }
    err := cmd.Start()
    if err != nil {
    fmt.Println("failed")
    }

    } else {
    if myarch == "386" {
    chrome := "google-chrome"
    } else {
    chrome := "google-chrome"
    }

     cmd := exec.Command(chrome, "--chrome-frame", url)
    err := cmd.Start()
    if err != nil {
    fmt.Println("failed")
    }
    

    }

    }

答案1

得分: 3

在Windows操作系统中:

对于Windows 7及更高版本:

你可以使用"HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome"来查找安装路径。实际上,这是从"HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications"中找到的"Google Chrome"键。

对于Windows XP到Vista:

你可以从"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome"中读取。我还没有验证过这个位置,请在你的XP机器上进行检查。

对于Mac操作系统:

你可以使用Chrome的bundle identifier(可以从info.plist中找到)来找到Chrome的安装位置。

英文:

In Windows,

Win 7 and high:

You can use "HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome" to find out install path. This actually coming from "Google Chrome" key found at "HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications".

Win XP to vista:

You could read from "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome". This location i have not verified, please do check if you have xp machine.

For Mac:

You can find chrome install location using chrome's bundle identifier (you could find this from info.plist).

huangapple
  • 本文由 发表于 2014年3月17日 17:16:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/22450445.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定