Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Temporarily disable CD/DVD drive to prevent spinning-up...?



  • Please log in to reply
19 replies to this topic
DTOXX
  • Members
  • 7 posts
  • Last active: Apr 11 2014 05:34 PM
  • Joined: 01 Jun 2013

Thanks, Lexikos, but my DVD drive is empty. 



Linear Spoon
  • Members
  • 842 posts
  • Last active: Sep 29 2015 03:56 AM
  • Joined: 29 Oct 2011

@DTOXX

Took a while to figure out what error -536870389 is. Perhaps this is a bug with AutoHotkey. According to the manual, A_LastError shouldn't be a negative value at all:

A_LastError is a number between 0 and 4294967295 ...

Anyway it is a valid error if you only look at the least significant 32 bits: ERROR_NO_SUCH_DEVINST. Unfortunately this is apparently an error reserved for the installer of the device specifically, so I'm not sure how to fix it. It seems to imply the device doesn't exist, yet the script would have stopped before that point if it didn't exist. MSDN isn't much help, either.

 

 

If you don't mind, try adding this after line 38 (after the loop, but before the end of the AutoExec section). It won't fix the script, but it would help determine if this is a valid method for determining if a device can be disabled and if it requires a restart to do so. This should be the same info as is displayed by the "DevNode Status" item in your device properties dialog.

VarSetCapacity(status, 4), VarSetCapacity(error, 4)
if r := DllCall("Cfgmgr32.dll\CM_Get_DevNode_Status", "ptr", &status, "ptr", &error, "uint", NumGet(di,20,"uint"), "uint", 0)
{
  Msgbox % "CM_Get_DevNode_Status failed: " r
  Exitapp
}
SetFormat, Integer, H
flags := NumGet(status,0,"uint")
Msgbox % "All flags: " flags "`nDN_DISABLEABLE: " (flags & 0x2000 ? "Yes" : "No") "`nDN_NEED_RESTART: " (flags & 0x100 ? "Yes" : "No")

Edit: Upon further testing, I think DN_NEED_RESTART is only set when a restart is actually needed, not if the device will need a reboot to change state. I'll add this to the scripts section after more bug-testing and usability improvements.


Join us at the new forum - http://www.ahkscript.org/

 


DTOXX
  • Members
  • 7 posts
  • Last active: Apr 11 2014 05:34 PM
  • Joined: 01 Jun 2013

I rebooted, added the code and this is what happened:

 

First message: 79888384

Second message: "CM_Get_DevNode_Status failed: 13"

 

Looks like that first error code has changed from its previous value of -40697856



Linear Spoon
  • Members
  • 842 posts
  • Last active: Sep 29 2015 03:56 AM
  • Joined: 29 Oct 2011

Error 13 is CR_NO_SUCH_DEVNODE. In my own testing I noticed this error always occurred for devices that at one time were connected but had been since disconnected (an old mouse and my iPod for example). Is that the case here? If not, then I'm sorry but I'm out of ideas.

 

Also, the value of hModule is okay if it varies. As long as it isn't 0 you're fine. Also after thinking about it I suppose in ERROR_NO_SUCH_DEVINST, DEVINST might mean "device installer" instead of "device instance"... but I don't know as the only information on this error is one line in the header file it's defined in. Doesn't even have a comment.

#define ERROR_NO_SUCH_DEVINST                    (APPLICATION_ERROR_MASK|ERROR_SEVERITY_ERROR|0x20B)

Join us at the new forum - http://www.ahkscript.org/

 


DTOXX
  • Members
  • 7 posts
  • Last active: Apr 11 2014 05:34 PM
  • Joined: 01 Jun 2013

I really appreciate your help, but I'm at a dead end as well. Thanks for your time and effort!