Biatu

Triggering "Scan for Hardware Changes"

5 posts in this topic

#1 ·  Posted (edited)

Hello, I found this func in the forums, but it does not work. I keep getting errors. I could use devcon but I will be using the script in a limited space environment.

 

ScanForHardwareChanges()

Func ScanForHardwareChanges() 
    Local Const $CM_LOCATE_DEVNODE_NORMAL = 0
    Local Const $CR_SUCCESS = 0
    $status = DLLCall("cfgmgr32.dll","int","CM_Locate_DevNode", _
            "int*",0,"int",0,"int",$CM_LOCATE_DEVNODE_NORMAL)
    
    If Not ($status[0] = $CR_SUCCESS) Then
        MsgBox(4096,"","CM_Locate_DevNode failed: " & $status[0])
        Return 0
    EndIf
    
    $status = DLLCall("cfgmgr32.dll","int","CM_Reenumerate_DevNode","int",$status[1],"int",0)
    
    If Not ($status[0] = $CR_SUCCESS) Then
        MsgBox(4096,"","CM_Reenumerate_DevNode failed: " & $status[0])
       printf("CM_Reenumerate_DevNode failed: %x\n", status));
        Return 0
    EndIf

    Return 1
EndFunc
 

 

Edited by Biatu

What is what? What is what.

Share this post


Link to post
Share on other sites



#2 ·  Posted

Share this post


Link to post
Share on other sites

#3 ·  Posted

yes, when running script as in on Win10 I get Error 51, on windows 7 I get error 5 (even with requireAdministrator set from Au3Wrapper), and...

if I change this line back to what it originally was...

$status = DLLCall("cfgmgr32.dll","int","CM_Locate_DevNode", _
            "int_ptr",0,"int",0,"int",$CM_LOCATE_DEVNODE_NORMAL)

I get error 3


What is what? What is what.

Share this post


Link to post
Share on other sites

#4 ·  Posted

Hmm, I'm not much help here.  I couldn't get it to run on windows 7 either.  I got the same error (5) which seems to indicate either an invalid DEVNODE or DEVINST from what I found an a header file (cfgmgr32.h) online.

#define CR_INVALID_DEVNODE                0x00000005
#define CR_INVALID_DEVINST          	  CR_INVALID_DEVNODE

Error 51 seems to indicate an access denied error.

#define CR_ACCESS_DENIED                  0x00000033

 

I'm not too sure where to troubleshoot from here.  Hopefully someone more familiar will chime in.

Share this post


Link to post
Share on other sites

#5 ·  Posted

It works for me in Windows 10 x64 Enterprise (required #RequireAdmin otherwise error 51), but not in Windows 7 x64 Enterprise (error 5).  Same user account on both, with Admin rights.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now