Open Windows tutorial after MSI installation

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
This commit is contained in:
Jason T. Greene
2022-06-16 21:34:57 -05:00
parent 05fc5959ec
commit ce3d0954a5
5 changed files with 638 additions and 3 deletions

View File

@ -12,6 +12,7 @@ import (
"syscall"
"unsafe"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
)
@ -26,6 +27,7 @@ const (
Environment = "Environment"
Add operation = iota
Remove
Open
NotSpecified
)
@ -37,6 +39,8 @@ func main() {
op = Add
case "remove":
op = Remove
case "open":
op = Open
}
}
@ -46,6 +50,14 @@ func main() {
os.Exit(ERR_BAD_ARGS)
}
// Hidden operation as a workaround for the installer
if op == Open && len(os.Args) > 2 {
if err := winOpenFile(os.Args[2]); err != nil {
os.Exit(OPERATION_FAILED)
}
os.Exit(0)
}
if err := modify(op); err != nil {
os.Exit(OPERATION_FAILED)
}
@ -182,3 +194,9 @@ func alert(caption string) int {
return int(ret)
}
func winOpenFile(file string) error {
verb, _ := syscall.UTF16PtrFromString("open")
fileW, _ := syscall.UTF16PtrFromString(file)
return windows.ShellExecute(0, verb, fileW, nil, nil, windows.SW_NORMAL)
}