System uptime su Windows, in stile Linux
scritto da Massimo il 3 Gennaio 2012 alle 21:32
archiviato in Windows
archiviato in Windows
L'uptime, per com'è conosciuto dai viziati Linux, su Windows manca e se ne sente la mancanza.
I comandi
Questo file VBS legge data e ora di avvio e restituisce il tempo trascorso:
I comandi
net statistics server o systeminfo riportano solamente la data e ora dell'ultimo avvio.
Questo file VBS legge data e ora di avvio e restituisce il tempo trascorso:
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /c net statistics server")
lineNum = 1
strText = ""
Do While Not objExecObject.StdOut.AtEndOfStream
strText = Trim(objExecObject.StdOut.ReadLine())
If lineNum = 4 Then
Exit Do
End If
lineNum = lineNum + 1
Loop
strDateTime = ""
For pos = 1 To Len(strText)
ch = Right(Left(strText, pos), 1)
If Asc(ch) >= 48 And Asc(ch) <= 57 Then
strDateTime = Right(strText, Len(strText) - pos + 1)
Exit For
End If
Next
dt = CDate(strDateTime)
diffS = Datediff("s", dt, Now)
diffM = Fix(diffS / 60)
diffS = diffS - (diffM * 60)
diffH = Fix(diffM / 60)
diffM = diffM - (diffH * 60)
diffD = Fix(diffH / 24)
diffH = diffH - (diffD * 24)
Dim tokens()
bounds = 0
If diffD > 0 Then
Redim Preserve tokens(bounds)
If diffD = 1 Then
tokens(bounds) = "1 day"
Else
tokens(bounds) = diffD & " days"
End If
bounds = bounds + 1
End If
If diffH > 0 Then
Redim Preserve tokens(bounds)
If diffH = 1 Then
tokens(bounds) = "1 hour"
Else
tokens(bounds) = diffH & " hours"
End If
bounds = bounds + 1
End If
If diffM > 0 Then
Redim Preserve tokens(bounds)
If diffM = 1 Then
tokens(bounds) = "1 minute"
Else
tokens(bounds) = diffM & " minutes"
End If
bounds = bounds + 1
End If
If diffS > 0 Then
Redim Preserve tokens(bounds)
If diffS = 1 Then
tokens(bounds) = "1 second"
Else
tokens(bounds) = diffS & " seconds"
End If
bounds = bounds + 1
End If
WScript.Echo "up " & Join(tokens, ", ")
Ultimi giorni di ferie, già mi manca il lavoro? :-)

Commenta