- Сообщения
- 4,020
- Репутация
- 626
Простенькие примеры по определению времени работы системы с использованием встроенных в саму систему функции systeminfo и в язык AutoIt - TimerDiff(0).
Через systeminfo
Для работы скрипта потребуется библиотека http://autoit-script.ru/index.php?topic=510.0
Через TimerDiff
Через WMI (автор - ynbIpb)
Через systeminfo
Код:
#include <Encoding.au3>
Uptime()
Func Uptime()
If StringInStr("0409 0809 0c09 1009 1409 1809 1c09 2009 2409 2809 2c09 3009 3409", @OSLang) Then
$sCommand = '"System Up Time"'
$sPattern = '(?s).+\s(\d+\sDays.*)\r\n'
$sMessage = 'System Up Time is '
ElseIf StringInStr('0419', @OSLang) Then
$sCommand = '"Время работы системы"'
$sPattern = '(?s).+\s(\d+\sдн\..*)\r\n'
$sMessage = 'Время работы системы '
EndIf
$hGUI = GUICreate('')
$pid = Run(@ComSpec & ' /c systeminfo | find ' & $sCommand, '', @SW_HIDE, 0x2)
$s = ''
While 1
$line = StdoutRead($pid)
If @error Then ExitLoop
If StringLen($line) > 0 Then $s &= $line
Wend
$s = StringRegExpReplace(_Encoding_866To1251($s), $sPattern, '\1')
MsgBox(64, 'System uptime', $sMessage & $s, 0, $hGUI)
GUIDelete($hGUI)
EndFunc
Через TimerDiff
Код:
MsgBox(48, 'System Up Time', 'System UP Time is ' & _UpTime())
Func _UpTime()
$iMSec = Int(TimerDiff(0))
$iSec = Int($iMSec/1000)
$iMSecDev = Mod($iMSec, 1000)
$sTime = $iSec & 'secs ' & $iMSecDev & 'msecs'
If $iSec >= 60 Then
$iMin = Int($iSec/60)
$iSecDev = Mod($iSec, 60)
$sTime = $iMin & 'mins ' & $iSecDev & 'secs ' & $iMSecDev & 'msecs'
If $iMin >= 60 Then
$iHr = Int($iMin/60)
$iMinDev = Mod($iMin, 60)
$sTime = $iHr & 'hrs ' & $iMinDev & 'mins ' & $iSecDev & 'secs ' & $iMSecDev & 'msecs'
If $iHr >= 24 Then
$iDay = Int($iHr/24)
$iHrDev = Mod($iHr, 24)
$sTime = $iDay & 'days ' & $iHrDev & 'hrs ' & $iMinDev & 'mins ' & $iSecDev & 'secs ' & $iMSecDev & 'msecs'
If $iDay >= 30 Then
$iMon = Int($iDay/30)
$iDayDev = Mod($iDay, 30)
$sTime = $iMon & 'months ' & $iDayDev & 'days ' & $iHrDev & 'hrs ' & $iMinDev & 'mins ' & $iSecDev & 'secs ' & $iMSecDev & 'msecs'
If $iMon >= 12 Then
$iYear = Int($iMon/12)
$iMonDev = Mod($iMon, 12)
$sTime = $iYear & 'yrs ' & $iMonDev & 'months ' & $iDayDev & 'days ' & $iHrDev & 'hrs ' & $iMinDev & 'mins ' & $iSecDev & 'secs ' & $iMSecDev & 'msecs'
EndIf
EndIf
EndIf
EndIf
EndIF
Return $sTime
EndFunc
Через WMI (автор - ynbIpb)
Код:
#include <Date.au3>
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$Output = ""
$Output &= "Computer: " & $strComputer & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_System", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
For $objItem In $colItems
$SystemUptime = ($objItem.SystemUpTime / 60)
Dim $SystemUptimeDay
Dim $SystemUptimeHour
Dim $SystemUptimeMin
Dim $SystemUptimeSec
$SystemUptimeDay = Int($objItem.SystemUpTime / 86400)
$SystemUptimeHour = Int($objItem.SystemUpTime / 3600) - ($SystemUptimeDay * 24)
$SystemUptimeMin = Int($objItem.SystemUpTime / 60) - ($SystemUptimeHour * 60) - ($SystemUptimeDay * 24 * 60)
$SystemUptimeSec = Int($objItem.SystemUpTime) - ($SystemUptimeMin * 60) - ($SystemUptimeHour * 60 * 60) - ($SystemUptimeDay * 24 * 60 * 60)
MsgBox(0, "Uptime: ", "Дней: " & $SystemUptimeDay & " Часов: " & $SystemUptimeHour & " Минут: " & $SystemUptimeMin & " Секунд: " & $SystemUptimeSec)
Next
Else
MsgBox(0, "Uptime", "No WMI Objects Found for class: " & "Win32_PerfFormattedData_PerfOS_System")
EndIf