You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
star/uac/cmd.go

55 lines
1.3 KiB
Go

2 years ago
//go:build windows
// +build windows
package uac
import (
"b612.me/starlog"
"github.com/spf13/cobra"
"os"
"path/filepath"
)
var fpath string
var fargs string
var workdir string
var showWindow bool
func init() {
Cmd.Flags().StringVarP(&fpath, "path", "p", "", "filepath/文件路径")
Cmd.Flags().StringVarP(&fargs, "args", "a", "", "args use space to split/参数,空格分隔")
Cmd.Flags().StringVarP(&workdir, "workdir", "d", "./", "workdir path")
Cmd.Flags().BoolVarP(&showWindow, "hide-window", "w", false, "hide the window show")
}
var Cmd = &cobra.Command{
Use: "uac",
Short: "run process with administrator permission",
Example: "vtqe uac 'c:\\program.exe arg1 arg2'",
Version: "2.0.0",
Run: func(cmd *cobra.Command, args []string) {
showWindow = !showWindow
workdir, _ = filepath.Abs(workdir)
if fpath == "" && len(args) == 0 {
starlog.Errorln("Please enter a filepath")
os.Exit(1)
}
if fpath != "" {
err := RunAsUacSimple(fpath, fargs, workdir, showWindow)
if err != nil {
starlog.Errorln("StartAsUac Failed", err)
os.Exit(2)
}
return
}
if len(args) > 0 {
err := RunAsUac(args[0], workdir, showWindow)
if err != nil {
starlog.Errorln("StartAsUac Failed", err)
os.Exit(2)
}
return
}
},
}