Sign in to follow this  
Followers 0
dickep

dll help please

6 posts in this topic

#1 ·  Posted (edited)

OK, I will admit I know nothing about how to call a dll for the information. I have looked on here and found some of what I want/need and now have another but no example.

I want to get more data from a laptop battery. I have used COMPINFO but some of the info is not either there or I cannot access it with this tool.

I have also done:

Global $SYSTEM_POWER_STATUS = DLLStructCreate("byte;byte;byte;byte;int;int")
$test = DLLCall("kernel32.dll","int","GetSystemPowerStatus", _
       "ptr",DllStructGetPtr($SYSTEM_POWER_STATUS))

to get the BatteryFlag information.

I still need some information.

According to Microsoft KB, there is a lot more ways to possibly get the battery information.

Here is the link to Battery_Status structure Battery_Status MSDN Topic and the SYSTEM_BATTERY_STATE sturcture SYSTEM_BATTERY_STATE MSDN topic

So, can someone give me how to call and use the information gathered?

Thanks

E

Edited by dickep

Share this post


Link to post
Share on other sites



dickep

Try this. Not tested, because i don`t have a laptop:

Dim $serial, $objWMIService, $colItems, $strComputer = ".", $ResultString

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_PortableBattery ")

For $objItem In $colItems
    $ResultString &= "Availability: " & $objItem.Availability & @LF
    $ResultString &= "Battery Recharge Time: " & $objItem.BatteryRechargeTime & @LF
    $ResultString &= "Battery Status: " & $objItem.BatteryStatus & @LF
    $ResultString &= "Capacity Multiplier: " & $objItem.CapacityMultiplier & @LF
    $ResultString &= "Chemistry: " & $objItem.Chemistry & @LF
    $ResultString &= "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @LF
    $ResultString &= "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @LF
    $ResultString &= "CreationClassName: " & $objItem.CreationClassName & @LF
    $ResultString &= "Description: " & $objItem.Description & @LF
    $ResultString &= "DesignCapacity: " & $objItem.DesignCapacity & @LF
    $ResultString &= "DesignVoltage: " & $objItem.DesignVoltage & @LF
    $ResultString &= "DeviceID: " & $objItem.DeviceID & @LF
    $ResultString &= "ErrorCleared: " & $objItem.ErrorCleared & @LF
    $ResultString &= "ErrorDescription: " & $objItem.ErrorDescription & @LF
    $ResultString &= "EstimatedChargeRemaining: " & $objItem.EstimatedChargeRemaining & @LF
    $ResultString &= "EstimatedRunTime: " & $objItem.EstimatedRunTime & @LF
    $ResultString &= "ExpectedBatteryLife: " & $objItem.ExpectedBatteryLife & @LF
    $ResultString &= "ExpectedLife: " & $objItem.ExpectedLife & @LF
    $ResultString &= "FullChargeCapacity: " & $objItem.FullChargeCapacity & @LF
    $ResultString &= "InstallDate: " & $objItem.InstallDate & @LF
    $ResultString &= "LastErrorCode: " & $objItem.LastErrorCode & @LF
    $ResultString &= "Location: " & $objItem.Location & @LF
    $ResultString &= "ManufactureDate: " & $objItem.ManufactureDate & @LF
    $ResultString &= "Manufacturer: " & $objItem.Manufacturer & @LF
    $ResultString &= "MaxBatteryError: " & $objItem.MaxBatteryError & @LF
    $ResultString &= "MaxRechargeTime: " & $objItem.MaxRechargeTime & @LF
    $ResultString &= "Name: " & $objItem.Name & @LF
    $ResultString &= "PNPDeviceID: " & $objItem.PNPDeviceID & @LF
    $ResultString &= "PowerManagementSupported: " & $objItem.PowerManagementSupported & @LF
    $ResultString &= "SmartBatteryVersion: " & $objItem.SmartBatteryVersion & @LF
    $ResultString &= "Status: " & $objItem.Status & @LF
    $ResultString &= "StatusInfo: " & $objItem.StatusInfo & @LF
    $ResultString &= "SystemCreationClassName: " & $objItem.SystemCreationClassName & @LF
    $ResultString &= "SystemName: " & $objItem.SystemName & @LF
    $ResultString &= "TimeOnBattery: " & $objItem.TimeOnBattery & @LF
    $ResultString &= "TimeToFullCharge: " & $objItem.TimeToFullCharge
Next

MsgBox(0, "", $ResultString)

Share this post


Link to post
Share on other sites

Did not get all the data. This was the same as COMPINFO.AU3 and I need to get the information from the DLL stuff, I think.

Surprised no one could direct me on how to setup and use the DLL's that I have referenced.

Thanks

E

Share this post


Link to post
Share on other sites

Did not get all the data. This was the same as COMPINFO.AU3 and I need to get the information from the DLL stuff, I think.

Surprised no one could direct me on how to setup and use the DLL's that I have referenced.

Thanks

E

Not everyone has a laptop to test them on... and those of us that do (don't necessarily have AutoIt installed on their laptop (that's me lol)).
Global $tag_BATTERY_STATUS = DllStructCreate("ulong[3];long")
Global $tag_SYSTEM_BATTERY_STATE = DllStructCreate("int[5];dword[6]")
Global $tag_SYSTEM_POWER_STATUS = DllStructCreate("byte[4];dword[2]")
Global $aBS = DllCall("Kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($tag_BATTERY_STATUS))
Global $aSBS = DllCall("Kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($tag_SYSTEM_BATTERY_STATE))
Global $aSPS = DllCall("Kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($tag_SYSTEM_POWER_STATUS))
;Battery Status
ConsoleWrite("Battery Status" & @CRLF)
For $i = 1 To 4
    ConsoleWrite($i & "). " & DllStructGetData($tag_BATTERY_STATUS, $i) & @CRLF)
Next
;System Battery State
ConsoleWrite(@CRLF & "System Battery State" & @CRLF)
For $i = 1 To 11
    ConsoleWrite($i & "). " & DllStructGetData($tag_SYSTEM_BATTERY_STATE, $i) & @CRLF)
Next
;System Power Status
ConsoleWrite(@CRLF & "System Power Status: " & @CRLF)
For $i = 1 To 6
    ConsoleWrite($i & "). " & DllStructGetData($tag_SYSTEM_POWER_STATUS, $i) & @CRLF)
Next
So without really knowing if the above actually outputs the correct info (Unable to test on a laptop), it's how I read them. And should be enough for you to do the others.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You made the Dllstructs the wrong way. This way it works:

Global $tag_BATTERY_STATUS = DllStructCreate("ulong;ulong;ulong;long")
Global $tag_SYSTEM_BATTERY_STATE = DllStructCreate("int;int;int;int;int[4];dword;dword;dword;dword;dword;dword")
Global $tag_SYSTEM_POWER_STATUS = DllStructCreate("byte;byte;byte;byte;dword;dword")
Global $aBS = DllCall("Kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($tag_BATTERY_STATUS))
Global $aSBS = DllCall("Kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($tag_SYSTEM_BATTERY_STATE))
Global $aSPS = DllCall("Kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($tag_SYSTEM_POWER_STATUS))
;Battery Status
ConsoleWrite("Battery Status" & @CRLF)
For $i = 1 To 4
    ConsoleWrite($i & "). " & DllStructGetData($tag_BATTERY_STATUS, $i) & @CRLF)
Next
;System Battery State
ConsoleWrite(@CRLF & "System Battery State" & @CRLF)
For $i = 1 To 11
    ConsoleWrite($i & "). " & DllStructGetData($tag_SYSTEM_BATTERY_STATE, $i) & @CRLF)
Next
;System Power Status
ConsoleWrite(@CRLF & "System Power Status: " & @CRLF)
For $i = 1 To 6
    ConsoleWrite($i & "). " & DllStructGetData($tag_SYSTEM_POWER_STATUS, $i) & @CRLF)
Next
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

You made the Dllstructs the wrong way. This way it works:

Global $tag_BATTERY_STATUS = DllStructCreate("ulong;ulong;ulong;long")
Global $tag_SYSTEM_BATTERY_STATE = DllStructCreate("int;int;int;int;int[4];dword;dword;dword;dword;dword;dword")
Global $tag_SYSTEM_POWER_STATUS = DllStructCreate("byte;byte;byte;byte;dword;dword")
Global $aBS = DllCall("Kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($tag_BATTERY_STATUS))
Global $aSBS = DllCall("Kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($tag_SYSTEM_BATTERY_STATE))
Global $aSPS = DllCall("Kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($tag_SYSTEM_POWER_STATUS))
;Battery Status
ConsoleWrite("Battery Status" & @CRLF)
For $i = 1 To 4
    ConsoleWrite($i & "). " & DllStructGetData($tag_BATTERY_STATUS, $i) & @CRLF)
Next
;System Battery State
ConsoleWrite(@CRLF & "System Battery State" & @CRLF)
For $i = 1 To 11
    ConsoleWrite($i & "). " & DllStructGetData($tag_SYSTEM_BATTERY_STATE, $i) & @CRLF)
Next
;System Power Status
ConsoleWrite(@CRLF & "System Power Status: " & @CRLF)
For $i = 1 To 6
    ConsoleWrite($i & "). " & DllStructGetData($tag_SYSTEM_POWER_STATUS, $i) & @CRLF)
Next
So I did.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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
Sign in to follow this  
Followers 0