I do this by using an autoit script. Now I wanted to do something better by reporting the lastbootup time in the Lansweeper database. Although I've tried to create a separated table that replicates the computername, it does not work as expected and I had no time until now to explore further, maybe I did something wrong (this was the script I've saved, I don't know how bad it is!)
🙂USE [Lansweeperdb]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[BBTtblUptimes](
[Computername] [int] NOT NULL,
[LastScanned] [datetime] DEFAULT (getdate()),
[Uptime] [nvarchar](255) NULL,
[UptimeID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
CONSTRAINT [PK_BBTtblUptimes] PRIMARY KEY CLUSTERED
(
[UptimeID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[BBTtblUptimes] WITH NOCHECK ADD CONSTRAINT [FK_BBTtblUptimes_tblComputers] FOREIGN KEY([Computername])
REFERENCES [dbo].[tblcomputers] ([Computername])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[BBTtblUptimes] CHECK CONSTRAINT [FK_BBTtblUptimes_tblComputers]
The AutoIt Function to retrieve uptime:
Func _RetrieveUptime($s_Machine)
Local $LastBootUp, $LocalDateTime, $sec, $uptime, $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20
Dim $objWMIService, $colItems
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $s_Machine & "\root\cimv2")
If IsObj($objWMIService) Then
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
For $objItem In $colItems
$LastBootUp = WMIDateStringToDate($objItem.LastBootUpTime)
$LocalDateTime = WMIDateStringToDate($objItem.LocalDateTime)
Next
$sec = _DateDiff("s", $LastBootUp, $LocalDateTime)
;$uptime = StringFormat("%.02d" & " " & "%.02d" & ":" & "%.02d", Mod($sec / 86400, 3600), Mod($sec / 3600, 24), Mod(($sec / 60), 60))
$uptime = $sec
$colItems = ""
$objWMIService = ""
Return $uptime
EndIf
EndFunc ;==>_RetrieveUptime
Lansweeper, can you please point me out how to create this table with cascade active correctly? Thanks.