I would like to run a script in Windows right before standby/sleep mode
You can use the Task Scheduler to create a task that is triggered by a Kernel-Power log event that indicates "Sleep":
- Run "Task Scheduler".
- Select "Task Scheduler Library
- Click menu "Action" > "Create Task"
- Select "General" and give the task a "Name" and Description"
Select "Triggers" and click "New"
- Set "Begin the Task" to "On an Event"
- Set "Log" to "System"
- Set "Source" to "Kernel-Power"
- Set "Event ID" to "42" (Sleep)
- Click "Ok"
Select "Actions" and click "New"
- Set "Program/script" to a script of your choice
- Click "Ok"
When I disable the corresponding device in the device manager everything works
I would like to automate this process.
Use devcon
to disable the device.
Notes:
- Use
devcon find
to get the device hardware ID. - Use
devcon disable HardwareID
to disable the device. - Add
devcon disable HardwareID
to the script created above. On Windows 7 64 bit you need to use the 32 bit version of
devcon
, as the 64 bit version gives the following error:This version of F:\test\devcon\ia64\devcon.exe is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need a x86 (32-bit) or x64 (64- bit) version of the program, and then contact the software publisher.
The download link mentioned below is a zip file containing both 32 and 64 bit versions of devcon.
Where do I download devcon?
Go to the http://support.microsoft.com page The DevCon command-line utility functions as an alternative to Device Manager for the download link.
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- devcon - Device Manager.