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.
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
//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: "以管理员权限运行程序",
|
|
Example: "b612 uac 'c:\\program.exe arg1 arg2'",
|
|
Version: "2.1.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
|
|
}
|
|
},
|
|
}
|