2

I would like to run a script in Windows right before standby/sleep mode with admin rights and blocking, i.e., the system should not go to sleep until the script has successfully terminated.

Alternatively, it would be possible for me to create a background process or service if it can be done in a simple manner.

Background: It seems I have a very buggy driver for a device which leaves Windows hanging with a blank screen when going to standby or presents a blank screen upon wakeup. This is not 100% reproduceable, it happens only sometimes. However, it seems when I just disable the corresponding device in the device manager, everything works fine. I would like to automate this process.

divB
  • 629

1 Answers1

2

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":

  1. Run "Task Scheduler".
  2. Select "Task Scheduler Library
  3. Click menu "Action" > "Create Task"
  4. Select "General" and give the task a "Name" and Description"
  5. 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"

    enter image description here

  6. Select "Actions" and click "New"

    • Set "Program/script" to a script of your choice
    • Click "Ok"

    enter image description here


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

DavidPostill
  • 162,382