This is a creation in
Article, where the information may have evolved or changed.
Package Mainimport ("Flag" "FMT") import (. "Github.com/codyguo/win") Var (arg string) func init () {flag. Stringvar (&arg, "uflags", "" "," Shutdown logoff reboot ")}func main () {flag. Parse () switch arg {case ' logoff ': Logoff () Case ' reboot ': Reboot () case "shutdown": Shutdown () default:fmt. PRINTLN ("The parameter you entered is incorrect.")}} Func logoff () {ExitWindowsEx (ewx_logoff, 0)}func reboot () {getprivileges () exitwindowsex (ewx_reboot, 0)}func shutdown ( ) {getprivileges () exitwindowsex (ewx_shutdown, 0)}func getprivileges () {var htoken handlevar TKP Token_ Privilegesopenprocesstoken (GetCurrentProcess (), token_adjust_privileges| Token_query, &htoken) Lookupprivilegevaluea (Nil, stringtobyteptr (se_shutdown_name), &TKP. Privileges[0]. LUID) TKP. Privilegecount = 1TKP. Privileges[0]. Attributes = Se_privilege_enabledadjusttokenprivileges (Htoken, False, &TKP, 0, Nil, nil)}