您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2025/12/3 16:29:47发布25次查看
下面由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定时关机的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product