package main import ( "io" "net/http" "log" "os/exec" "fmt" "time" ) /* https://www.cnblogs.com/TianFang/p/7912648.html 封装服务看这里 http://ip/s 手机上浏览器访问这个url 电脑进入休眠 开发者wechat:ipub520 */ func HelloServer(w http.ResponseWriter, req *http.Request) { io.WriteString(w, "30秒后电脑进入休眠!\n") time.Sleep(30*time.Second) c := exec.Command("cmd", "/C", "rundll32.exe powrprof.dll,SetSuspendState 0,1,0", "D:\\a.txt") if err := c.Run(); err != nil { fmt.Println("Error: ", err) } } func main() { http.HandleFunc("/s", HelloServer) err := http.ListenAndServe(":81", nil) if err != nil { log.Fatal("ListenAndServe: ", err) } }
下载源码文件及exe:
https://files.cnblogs.com/files/ipub520/standby.zip
原文地址:https://www.cnblogs.com/ipub520/p/8319873.html
时间: 2024-11-01 12:08:02