How to get uptime using BGinfo on desktop?

237 Views Asked by At

here the example of the system uptime

I need assistance in obtaining the system uptime using BGinfo.

I have tried various methods, including PowerShell and VBScript, but unfortunately, I haven't been able to display the uptime information on the BGinfo desktop wallpaper.

Can anyone help me with this issue? Your assistance would be greatly appreciated.

Thanks

I have attempted to retrieve the system uptime value using various methods, including WMI, PowerShell, and VBS scripts. However, I am facing difficulties in integrating the PowerShell script into the BGinfo application. Here is the PowerShell script that I have been working with to obtain the system uptime:

$ComputerName = $env:COMPUTERNAME
$userSystem = Get-WmiObject win32_operatingsystem -ComputerName $ComputerName -ErrorAction SilentlyContinue
if ($userSystem.LastBootUpTime) {
    $sysuptime= (Get-Date) - 
    $userSystem.ConvertToDateTime($userSystem.LastBootUpTime)
    Write-Output ("Last boot: " + 
    $userSystem.ConvertToDateTime($userSystem.LastBootUpTime) )
    Write-Output ("Uptime : " + $sysuptime.Days + " Days " + 
    $sysuptime.Hours + " Hours " + $sysuptime.Minutes + " Minutes" )
}
else {
    Write-Warning "Unable to connect to $computername"
}

I would like to learn how to incorporate a PowerShell script into the BGinfo application to display the system uptime information on the desktop. By integrating the PowerShell script with BGinfo, I aim to show the current system's uptime as part of the desktop information. Any guidance or instructions on how to achieve this would be highly appreciated.

1

There are 1 best solutions below

1
Karim On
Dim ComputerName
Dim userSystem
Dim sysuptime
Dim lastBootUpTime

ComputerName = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%COMPUTERNAME%")

Set objWMIService = GetObject("winmgmts:\\" & ComputerName & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")

For Each objItem In colItems
    lastBootUpTime = objItem.LastBootUpTime
Next

If Not IsNull(lastBootUpTime) Then
    lastBootUpTime = CDate(Mid(lastBootUpTime, 1, 4) & "-" & Mid(lastBootUpTime, 5, 2) & "-" & Mid(lastBootUpTime, 7, 2) & " " & Mid(lastBootUpTime, 9, 2) & ":" & Mid(lastBootUpTime, 11, 2) & ":" & Mid(lastBootUpTime, 13, 2))
    
    sysuptime = DateDiff("s", lastBootUpTime, Now())
    Days = Int(sysuptime / 86400)
    Hours = Int((sysuptime Mod 86400) / 3600)
    Minutes = Int(((sysuptime Mod 86400) Mod 3600) / 60)
    
    lastBootUpTimeString = FormatDateTime(lastBootUpTime, vbLongDate)
    
    Echo "Last boot: " & lastBootUpTimeString
    Echo "Uptime: " & Days & " Days " & Hours & " Hours " & Minutes & " Minutes"
Else
    Echo "Unable to connect to " & ComputerName
End If