优秀的编程知识分享平台

网站首页 > 技术文章 正文

Win10定时休眠和唤醒 win10定时唤醒睡眠

nanyue 2024-12-15 15:54:01 技术文章 7 ℃

执行场景:

早上 8 点,自动唤醒电脑,登录微信、钉钉;

下午 6 点,弹窗询问是否休眠,确定后,杀掉微信、钉钉进程,进入休眠状态。

完整的Windows定时休眠/唤醒流程,适用人群场景为『995常规社畜』

休眠

1、开启休眠选项

设置 cmd

# 查询电源选项
powercfg /a
# 开启休眠选项
powercfg -h on

2、 打开休眠菜单

依次打开并勾选:

控制面板\硬件和声音\电源选项\系统设置\更改当前不可用的设置\休眠

3、配置休眠脚本

选择一个合适的位置,比如 D:\shutdown

右键空白处新建文档,将以下内容复制粘贴

另存为 shutdownh.vbs

选择格式为 ANSI,否则不能正常使用

脚本

' 获取当前程序所在的文件位置
Dim strWorkDir
strWorkDir = Left(WScript.ScriptFullName,instrrev(WScript.ScriptFullName,"\")-1)

' 加载配置文件
dim fso
config = strWorkDir & "\kill.txtc"

' 设置杀掉进程
dim items
set fso = CreateObject("Scripting.FileSystemObject")
if fso.FileExists(config) then
    set f = fso.OpenTextFile(config, 1, false)
	items = f.ReadLine()
	f.Close()
	set f = nothing
	set fso = nothing
else
	If MsgBox("在休眠时需要指定关闭进程么?",vbOKCancel) = VbOk Then
		items = InputBox("输入你休眠时需要杀掉的进程,多个进程使用空格分开")
		set f = fso.CreateTextFile(config, true)
		f.Write(items)
		f.Close()
		set f = nothing
		set fso = nothing
	End If
End If

' 关机操作
Set WshShell = CreateObject("Wscript.Shell")
w = WshShell.Popup("下班了,需要休眠吗?不操作10分钟后自动关机", 600, "下班提醒",vbOKCancel)
If w = vbOk Or w <> vbCancel Then
    If Not IsEmpty(items) then
        ' 千万不要在前面加 dim,dim 只能用来声明不能赋值
        ' dim process = split(items," ")
        process = split(items," ")
        for each item in process
            WshShell.run "taskkill /f /im " & item, 0
        next
    End If
	WshShell.run "shutdown -h",0
End If

4、配置定时任务

设置休眠的时间每天下午的5:30(按照你的需求时间自行修改),执行程序 D:\shutdown\shutdownh.vbs。

cmd 命令创建

schtasks.exe /create /tn "自动休眠" /ru SYSTEM /sc daily /tr "D:\shutdown\shutdownh.vbs" /st 17:30

5、关于杀死进程

解释一下为什么休眠要杀掉某些进程,第一有些进程会在挂起后持续吃内存导致系统变的卡顿;第二有些进程一直挂在后台不安全,比如微信/qq等等。

第一次询问的时候把要杀死的进程写进去,休眠的时候会自动关闭的,这里举了一些比较常用的例子

  • WeChat.exe
  • WeChatApp.exe
  • Qq.exe
  • DingTalk.exe

电脑休眠其他的程序不会关闭,但是微信、钉钉是必须要关的,为了安全起见。

# 查看进程列表
tasklist
# 查看进程正在试用的模块
tasklist /m
# 查询指定的dll文件正在被谁使用
tasklist /m:XXX.dll

手动创建

我的电脑\此电脑\右键管理\创建计划任务

唤醒

自动唤醒配合工具 WakeupOnStandBy

配置如 图

最近发表
标签列表