Advertisement
Guest User

Functions.au3

a guest
Jun 14th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.00 KB | None | 0 0
  1. Func _GetNetConnection()
  2.     Local $aReturn = DllCall('connect.dll', 'long', 'IsInternetConnected')
  3.     If @error Then
  4.         Return SetError(1, 0, False)
  5.     EndIf
  6.     Return $aReturn[0] = 0
  7. EndFunc ;==>_IsInternetConnected
  8.  
  9. Func _Battery_StartUp()
  10.     Local $o_WMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
  11.     Return $o_WMIService.ExecQuery("SELECT * FROM Win32_Battery", "WQL", 48)
  12. EndFunc
  13.  
  14. Func _Battery_IsCharging()
  15.     Local $o_item, $_state = Default, $o_object = _Battery_StartUp()
  16.     If IsObj($o_object) Then
  17.         For $o_item in $o_object
  18.             $_state = $o_item.BatteryStatus
  19.         next
  20.         If $_state < 0 Or $_state > 7 Then
  21.             Return SetError(-2)
  22.         Else
  23.             If $_state = 2 Then
  24.                 Return True
  25.             Else
  26.                 Return False
  27.             EndIf
  28.         EndIf
  29.     Else
  30.         Return SetError(-1)
  31.     EndIf
  32. EndFunc
  33.  
  34. Func _Battery_GetCharge()
  35.     Local $o_item, $o_object = _Battery_StartUp()
  36.     If IsObj($o_object) Then
  37.         For $o_item in $o_object
  38.             Return $o_item.EstimatedChargeRemaining
  39.         Next
  40.     Else
  41.         Return SetError(-1)
  42.     EndIf
  43. EndFunc
  44.  
  45. Func _Battery_GetVoltage()
  46.     Local $o_item, $o_object = _Battery_StartUp()
  47.     If IsObj($o_object) Then
  48.         For $o_item in $o_object
  49.             Return ($o_item.DesignVoltage/1000)
  50.         Next
  51.     Else
  52.         Return SetError(-1)
  53.     EndIf
  54. EndFunc
  55.  
  56. Func GetCPUUsage()
  57.     Local $wbemFlags = 0x10 + 0x20
  58.  
  59.     Local $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
  60.     Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", $wbemFlags)
  61.  
  62.     Local $c = 0
  63.     Local $sMsg = ""
  64.  
  65.     For $objItem In $colItems
  66.         $sMsg &= "cpu%" & $objItem.LoadPercentage
  67.     Next
  68.  
  69.     $CpuAuslastung = StringSplit($sMsg, "cpu%", 1)
  70.  
  71.     For $n = "0" To $CpuAuslastung[0]
  72.         $c += $CpuAuslastung[$n]
  73.     Next
  74.  
  75.     Return (Round($c / $CpuAuslastung[0], 0))
  76. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement