您好,欢迎访问一九零五行业门户网

golang怎么编写一个window定时关机

下面由golang教程栏目给大家介绍golang编写一个window定时关机 ,希望对需要的朋友有所帮助!
代码如下:
package mainimport (    flag    fmt    github.com/robfig/cron    time)import (    . github.com/codyguo/win)var (    arg string)func init() {    flag.stringvar(&arg, uflags, shutdown, shutdown logoff reboot)}func main() {    flag.parse()    c := cron.new(cron.withseconds())    c.addfunc(0 40 18 * * ?, shutdown)    c.start()    select {}    switch arg {    case logoff:        logoff()    case reboot:        reboot()    case shutdown:        shutdown()    default:        fmt.println(您输入的参数有误.)    }}func test(){    fmt.println(time.now())}func logoff() {    exitwindowsex(ewx_logoff, 0)}func reboot() {    getprivileges()    exitwindowsex(ewx_reboot, 0)}func shutdown() {    getprivileges()    exitwindowsex(ewx_shutdown, 0)}func getprivileges() {    var htoken handle    var tkp token_privileges    openprocesstoken(getcurrentprocess(), token_adjust_privileges|token_query, &htoken)    lookupprivilegevaluea(nil, stringtobyteptr(se_shutdown_name), &tkp.privileges[0].luid)    tkp.privilegecount = 1    tkp.privileges[0].attributes = se_privilege_enabled    adjusttokenprivileges(htoken, false, &tkp, 0, nil, nil)}
cron表达式
c.addfunc(0 40 18 * * ?, shutdown)
以上就是golang怎么编写一个window定时关机的详细内容。
其它类似信息

推荐信息