截断 SystemInfo/Boot Time 输出并设置为变量?

Truncate SystemInfo / Boot Time output and set as a variable?

我正在制作一个批处理脚本来检查本地联网的 PC,并希望将每台 PC 的启动时间或正常运行时间设置为一个变量,以便我可以随心所欲地显示数据。

我使用这个命令打印到屏幕:

SystemInfo /s PC_NAME | find "Boot Time:"

得到这个结果:

System Boot Time:          27/09/2019, 9:15:16 AM

但我只想将“27/09/2019,9:15:16 AM”部分设置为变量。

谢谢

虽然我确定会有更有效的方法,但我想通了:

@ECHO Off
SET PC_NAME=BillyPC
SET TEMP_FILE=C:\temp\temp.txt
SystemInfo /s %PC_NAME% | FIND "Boot Time:" > %TEMP_FILE%
SET /p BOOT_TIME=<%TEMP_FILE%
SET BOOT_TIME=%BOOT_TIME:~27%
ECHO %BOOT_TIME%
PAUSE

干杯

请注意系统信息已本地化。所以 "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)