请注意 systeminfo 已本地化。所以 "Boot Time" 仅适用于英文版的 Windows。
因此,最好将 WMIC 用于任何系统语言,如下面的代码:
@echo off
Title Last Boot Time
for /f %%a in ('WMIC OS GET lastbootuptime ^| find "."') DO set "DTS=%%a"
set "BOOTTIME=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2% %DTS:~8,2%:%DTS:~10,2%"
echo DTS : %DTS%
echo BOOTTIME : %BOOTTIME%
pause
如果你喜欢这样的 vbscript:
Option Explicit
' Declare variables
Dim colItems, objItem, objWMIService,ws,Title
Dim strBoot, strBootDate, strBootDay, strBootHour, strBootMins
Dim strBootMonth, strBootTime, strBootYear, strComputer, strMsg, strQuery
Title = "La dernière heure de démarrage de votre ordinateur by Hackoo 2018"
Set ws = CreateObject( "WScript.Shell" )
strComputer = ws.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
If IsEmpty(strComputer) Then
WScript.quit()
ElseIf strComputer = "" Then
strComputer = "."
End If
' Connect to specified computer
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
Set colItems = objWMIService.ExecQuery( "Select * from Win32_OperatingSystem", , 48 )
For Each objItem in colItems
strBootYear = Left( objItem.LastBootUpTime, 4 )
strBootMonth = Mid( objItem.LastBootUpTime, 5, 2 )
strBootDay = Mid( objItem.LastBootUpTime, 7, 2 )
strBootDate = DateValue( strBootDay & "-" & strBootMonth & "-" & strBootYear )
strBootHour = Mid( objItem.LastBootUpTime, 9, 2 )
strBootMins = Mid( objItem.LastBootUpTime, 11, 2 )
strBootTime = strBootHour & ":" & strBootMins
strBoot = strBootDate & ", " & strBootTime
strMsg = "La dernière heure de démarrage du PC : " & chr(34) & strComputer & chr(34) & " est : " &_
vbCrlf & strBoot
Next
' Display results
MsgBox strMsg,vbInformation,Title
'Done
WScript.Quit(0)