Jump to content

Device Management API


weaponx
 Share

Recommended Posts

_WinAPI_Check() was deprecated in 3.3.2.0

Just paste this in somewhere:

Func _WinAPI_Check($sFunction, $fError, $vError, $fTranslate = False)
    If $fError Then
        If $fTranslate Then $vError = _WinAPI_GetLastErrorMessage()
        _WinAPI_ShowError($sFunction & ": " & $vError)
    EndIf
EndFunc ;==>_WinAPI_Check
Link to comment
Share on other sites

  • Replies 76
  • Created
  • Last Reply

Top Posters In This Topic

Sorry for the necropost, but this looks too awesome to not use! When I check DeviceAPI I get

DeviceAPI.au3(684,73) : ERROR: _WinAPI_Check(): undefined function

Did something change in Alpha 5 that nobody mentioned until now?? Commenting out the 2 lines with that function call did allow it to work, but the error checking might be a nice thing to have...

Thanks

Ian

The _WinAPI_Check() function was removed from the Betas back in October 2009 in 3.3.1.2:

- Removed #1112: __WinAPI_Check() has been removed as have all calls to it.

The comments by Valik in BugTrac #1112 make it look like the particular errors it was intended to check for have been debugged out of AutoIt.

;)

Edit: Oops, weaponx is already on it. :-)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Great, thanks guys!

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

How is work on this UDF coming weaponx? Have you gotten any more functions working? I would like to have a native AutoIt way to install a driver, I have done it with devcon through AutoIt many times but native it always nicer ;)

Thanks

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

OK, odd one here. Using DeviceAPI.au3 over the network results in all null returns. An excerpt of my code is:

#include "DeviceAPI.au3"
#include "file.au3"
#include "array.au3"
#include "GUIConstantsEx.au3"
#include "ProgressConstants.au3"

local $HWID
local $availableHWID
local $foundamatch
local $previousFound

;Build list of devices, strip out ones without an HWID
_DeviceAPI_GetClassDevices()
$Count = 0
;Loop through all devices by index
While _DeviceAPI_EnumDeviceInfo($Count)
    
;~  ConsoleWrite("+"& _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DEVICEDESC) & @CRLF)
;~  ConsoleWrite("Hardware ID: " & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_HARDWAREID) & @CRLF)
    
    $haveHWID=_DeviceAPI_GetDeviceRegistryProperty($SPDRP_HARDWAREID)
    if $haveHWID<>"" then 
        $HWID&=_DeviceAPI_GetDeviceRegistryProperty($SPDRP_DEVICEDESC)&chr(2)&_DeviceAPI_GetDeviceRegistryProperty($SPDRP_HARDWAREID)&chr(2)
    EndIf
    
    $Count += 1
WEnd

Tossing in a MsgBox to state the _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DEVICEDESC) or DeviceAPI_GetDeviceRegistryProperty($SPDRP_HARDWAREID) gives up nada if the script is run over the network, works fine if run local. hehehehehe, any ideas in that one? ;)

PS This is part of a driver installer by HWID, works GREAT, local. But I want it to work over the LAN like my previous version did, but that was using Devcon......

Thanks

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

Did something change in Alpha 5 that nobody mentioned until now?? Commenting out the 2 lines with that function call did allow it to work, but the error checking might be a nice thing to have...

See about locomotions of _WinAPI_Check() here

The last version:

; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_Check
; Description ...: Displays any errors produced by the AutoIt library
; Syntax.........: _WinAPI_Check($sFunction, $fError, $vError[, $fTranslate = False])
; Parameters ....: $Function     - Name of function
;                  $fError       - True if error occurred
;                  $iError       - Error code
;                  $fTranslate   - Translate error using _WinAPI_GetLastErrorMessage
; Return values .:
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; Remarks .......: This function is used within many of the lower level API functions to simulate a  "fatal"  application  error.
;                  It is used in functions that normally should not fail or where there is no clear corrective action that can be
;                  taken if an error is generated.
; Related .......: _WinAPI_GetLastErrorMessage
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _WinAPI_Check($sFunction, $fError, $vError, $fTranslate = False)
    If $fError Then
        If $fTranslate Then $vError = _WinAPI_GetLastErrorMessage()
        _WinAPI_ShowError($sFunction & ": " & $vError)
    EndIf
EndFunc   ;==>_WinAPI_Check

The point of world view

Link to comment
Share on other sites

thanks for this, one small thing i ended up adding to the GUI example though :D

added at the end of the script just underneath "WEnd"

_GUICtrlListView_SetColumnWidth($hListView,0,$LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($hListView,1,$LVSCW_AUTOSIZE)

added directly above your "While 1" loop

_GUICtrlTreeView_Sort($hTreeView)
Edited by bluechipps
Link to comment
Share on other sites

OK, odd one here. Using DeviceAPI.au3 over the network results in all null returns. An excerpt of my code is:

I didn't include support for remote machines. It probably isn't that much work either, some function names just need switched out and more parameters added.

SetupDiGetClassImageList -> SetupDiGetClassImageListEx

SetupDiGetClassDevs -> SetupDiGetClassDevsEx

SetupDiBuildClassInfoList -> SetupDiBuildClassInfoListEx

SetupDiGetClassDescription -> SetupDiGetClassDescriptionEx

SetupDiClassNameFromGuid -> SetupDiClassNameFromGuidEx

Link to comment
Share on other sites

  • 2 weeks later...

It looks like this:

#include "DeviceAPI.au3"
_DeviceAPI_GetClassDevices("{4D36E978-E325-11CE-BFC1-08002BE10318}")
$Count = 0
While _DeviceAPI_EnumDeviceInfo($Count)
    $friendly_name = _DeviceAPI_GetDeviceRegistryProperty($SPDRP_FRIENDLYNAME)
    $Count += 1
    If Not StringInStr($friendly_name,'(COM') Then ContinueLoop
    ConsoleWrite($friendly_name & @CRLF)
WEnd
Edited by Odin
Link to comment
Share on other sites

  • 4 months later...

Looking over your code and your example, I can't figure out how I can remove a device. Have you implemented this ability yet?

Thanks!

EDIT: more specifically I need to remove devices that have been disconnected. Essentially those that show when I run "devcon findall *" but not "devcon find *".

This is for a installation wrapper I am writing... if you install on a system that had an old version of the software on it, the new drivers aren't installed properly unless you first remove the old devices in device manager (or with devcon). Since the manufacturer's installer doesn't first remove the old devices, I must do it with AutoIT. If I can do it without devcon I would be thrilled.

Edited by jhfry
Link to comment
Share on other sites

You should made a application that finds the actual driver locations for each object, and then copy them all in to one folder, that way after wiping you could install them all in seconds. =]

Just a suggestion since I see you would most likley know how to get the locations of the drivers.

[center][/center][center]=][u][/u][/center][center][/center]

Link to comment
Share on other sites

You should made a application that finds the actual driver locations for each object, and then copy them all in to one folder, that way after wiping you could install them all in seconds. =]

Just a suggestion since I see you would most likley know how to get the locations of the drivers.

You can get this information by using
$string = _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DRIVER),
Take the result (here I used $string), and find that in the registry in KEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum. In the value name "Mfg" find the INF file name, which can be found in C:\Windows\Inf. Now the harder part, you will have to parse that file and look for the actual driver files, then locate them in various C:\Windows subfolders (INF, Drivers, DriverRepository, etc etc etc).

I have never written a tool to parse the INFs in that way, only to extract HWIDs for an installer I was working on. Doing a parser like this would be great fun to do but is currently sitting about 10-projects down on my totem pole right now!! Hopefully this will at least give you a start.

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

You can get this information by using

$string = _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DRIVER),
Take the result (here I used $string), and find that in the registry in KEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum. In the value name "Mfg" find the INF file name, which can be found in C:\Windows\Inf. Now the harder part, you will have to parse that file and look for the actual driver files, then locate them in various C:\Windows subfolders (INF, Drivers, DriverRepository, etc etc etc).

I have never written a tool to parse the INFs in that way, only to extract HWIDs for an installer I was working on. Doing a parser like this would be great fun to do but is currently sitting about 10-projects down on my totem pole right now!! Hopefully this will at least give you a start.

Ian

thanks i will look into this.

[center][/center][center]=][u][/u][/center][center][/center]

Link to comment
Share on other sites

You should made a application that finds the actual driver locations for each object, and then copy them all in to one folder, that way after wiping you could install them all in seconds. =]

Just a suggestion since I see you would most likley know how to get the locations of the drivers.

Thanks, but it doesn't solve my problem of REMOVING the devices from the system.

The drivers aren't my issue... the 3rd party installer takes care of installing them... but unless I remove the old version first there is some sort of conflict (not sure what) and the device doesn't work.

Please understand that this is an installation wrapper that is slated to be pushed out to 10,000+ computers. Right now I can do it all with DEVCON... and it works... I would just like to keep it pure AutoIT if possible.

Here is what my code looks like now, using DEVCON... maybe that will give you some idea of what my objective is.

Func RemoveBlackBerryDevices()
    WriteLog("Starting Device Removal")

    ;define local variables
    Local $removed = 0
    Local $found = 0
    Local $cmd, $pid, $output, $outputArray, $devices

    ;extract devcon.exe
    WriteLog("Extracting devcon.exe to temporary directory")
    $Result = FileInstall("files\devcon.exe", $TEMP_DIR, 1)
    If $Result < 1 Then WriteLog("Error extracting Device Removal files", True) ;write error and exit
    WriteLog("Extraction successful")

    ;enumerate blackberry related devices
    WriteLog("Enumerating Blackberry Devices")
    $cmd = "devcon findall ""*0fca*"" ""@*blackberry*"" ""*rimports*"" ""@STORAGE\REMOVABLEMEDIA*"""
    WriteLog("Executing: " & $cmd)
    $pid = Run(@ComSpec & " /c " & $cmd, $TEMP_DIR, @SW_HIDE, $STDOUT_CHILD)
    If @error Then WriteLog("Command Failed", True)
    $output = ""
    While 1
        $output &= StdoutRead($pid)
        if @error Then ExitLoop
    WEnd

    ;generate an array of each line of the output
    $outputArray = StringSplit($output, @CR)

    ;generate the devices array by splitting each element in the $output array into device instance ID and name
    Dim $devices[$outputArray[0] + 1][2] ;the length of the array is the same as the output array, plus 1 to hold the size in 0,0
    For $i = 1 to $outputArray[0]
        If StringInStr($outputArray[$i], "matching device") Then
            $devices[0][0] = $i - 1 ;put the number of devices in the array in 0,0
            ExitLoop
        EndIf
        If StringInStr($outputArray[$i], ":") > 0 Then
            $devices[$i][0] = StringStripWS(StringLeft($outputArray[$i], StringInStr($outputArray[$i], ":")-1),3)
            $devices[$i][1] = StringStripWS(StringMid($outputArray[$i], StringInStr($outputArray[$i], ":")+1),3)
        Else
            $devices[$i][0] = StringStripWS($outputArray[$i],3)
            $devices[$i][1] = "Unnamed device"
        EndIf
        WriteLog("Found: " & $devices[$i][1] & " - " & $devices[$i][0])
        $found += 1
    Next
    WriteLog($found & " device(s) found")

    ;remove devices
    For $i = 1 to $devices[0][0]
        WriteLog("Attempting to remove " & $devices[$i][1] & " - " & $devices[$i][0])
        $cmd = "devcon remove ""@" & $devices[$i][0]& """"
        WriteLog("Executing: " & $cmd)
        $pid = Run(@ComSpec & " /c " & $cmd, $TEMP_DIR, @SW_HIDE, $STDOUT_CHILD)
        If @error Then WriteLog("Command Failed", True)
        $output = ""
        While 1
            $output &= StdoutRead($pid)
            if @error Then ExitLoop
        WEnd
        $results = StringSplit($output, @CR, 1)
        WriteLog($devices[$i][1] & " - " & $results[1])
        $removed += Number($results[2])
    Next
    WriteLog($removed & " devices removed")
EndFunc

I have to believe that this could be simplified with the OP's UDF... but I need the ability to remove devices with it or it doesn't really do me much good.

Link to comment
Share on other sites

Thanks, but it doesn't solve my problem of REMOVING the devices from the system.

.

.

.

I have to believe that this could be simplified with the OP's UDF... but I need the ability to remove devices with it or it doesn't really do me much good.

I too would love to see that kind of functionality, and no doubt weaponx would as well. He is one of the sickest coders here, always great stuff, I use several of his snippets literally every day. Be patient. :mellow:

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

I'll see what I can do. As of right now the UDF only retrieves information. I intended it to do everything Devcon can but testing it is very tricky if I want to avoid hosing my system.

Link to comment
Share on other sites

I'll see what I can do. As of right now the UDF only retrieves information. I intended it to do everything Devcon can but testing it is very tricky if I want to avoid hosing my system.

I run a computer repair shop so I have access to tons of machines that are getting clean Windows installs, I'll beta anything you need bro! :mellow:

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...