Last active
August 1, 2017 09:25
-
-
Save piroor/8bd722c2a287057f744d3a750a916de1 to your computer and use it in GitHub Desktop.
Golang study
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"golang.org/x/sys/windows/registry" | |
) | |
func main() { | |
fmt.Printf(GetIEPath()) | |
} | |
func GetIEPath() (path string) { | |
key, err := registry.OpenKey(registry.LOCAL_MACHINE, | |
`SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\iexplorer.exe`, | |
registry.QUERY_VALUE) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer key.Close() | |
path, _, err = key.GetStringValue("") | |
if err != nil { | |
log.Fatal(err) | |
} | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"os/exec" | |
"golang.org/x/sys/windows/registry" | |
) | |
func main() { | |
ieapp := GetIEPath() | |
ieargs := []string{"-e"} | |
LaunchIE(ieapp, ieargs, "https://github.com/") | |
} | |
func LaunchIE(ieapp string, ieargs []string, url string) { | |
args := append(ieargs, url) | |
command := exec.Command(ieapp, args...) | |
err := command.Start() | |
if err != nil { | |
log.Fatal(err) | |
} | |
} | |
func GetIEPath() (path string) { | |
key, err := registry.OpenKey(registry.LOCAL_MACHINE, | |
`SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\iexplore.exe`, | |
registry.QUERY_VALUE) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer key.Close() | |
path, _, err = key.GetStringValue("") | |
if err != nil { | |
log.Fatal(err) | |
} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment