I have a program that I want to run automatically when turning on my Windows 10 laptop from sleep or hibernate mode without logging in yet. If the program is ran, there should be a command prompt displayed. I have tried putting the program into the Windows Startup folder but the program only automatically runs when I turn on the laptop from shutdown mode. Also, I have tried creating a task in the Task Scheduler to run the task using triggers like "On an event (Log: System, Source: Microsoft-Windows-Power-Troubleshooter, Event ID: 1)" and "On workstation unlock", but my program doesn't start when turning on my laptop from sleep or hibernate mode (I logged in to see if the program was on but it wasn't). It doesn't look like there is any Trigger named "On Wake" or anything like that. If anyone has any suggestions on how to get this to work, I'd greatly appreciate this!
Set colMonitoredEvents = GetObject("winmgmts:")._ ExecNotificationQuery("SELECT * FROM Win32_PowerManagementEvent") Do Set strLatestEvent = colMonitoredEvents.NextEvent If strLatestEvent.EventType = 4 Then Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * From Win32_Process") For Each objItem in colItems If objItem.name = "Calculator.exe" then objItem.terminate Next ElseIf strLatestEvent.EventType = 7 Then wscript.sleep 2000 Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "calc.exe", 1, false End If Loop
This script waits for the system to suspend and terminates calculator, if running. On resume it restarts calculator.
Name the script something.vbs. Double click to run it. It is invisible. In task manager it is called wscript.exe.
See https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-powermanagementevent for documentation.