→ 🚀What's New? Join Us for the Fall Product Launch! Register Now !

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
austin99
Engaged Sweeper
Can you tell me where I can pull the last boot time for a system? I know they're usually noted with a 6009 entry in the eventlog, but I'm wondering if they're stored somewhere else in the database. I'm building a report to show last patching information and the last boot time would help me determine if policies are being applied correctly.
7 REPLIES 7
Anonymous
Not applicable
ok, thanks. But in case of deletion if cascade is on, it will be deleted, right?
Hemoco
Lansweeper Alumni
BullGates wrote:
ok, thanks. But in case of deletion if cascade is on, it will be deleted, right?

Yes, if the computername changes in table tblcomputers, then the other table will be updated.
Hemoco
Lansweeper Alumni
It won't work like that, you will need to query tblcomputers to get the correct computername and insert it into the table.
Anonymous
Not applicable
I don't get any error, but I wanted the field "Computername" to be automatically replicated from the table "tblcomputers", and that is not working.
Anonymous
Not applicable
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.
Hemoco
Lansweeper Alumni
BullGates wrote:
Lansweeper, can you please point me out how to create this table with cascade active correctly? Thanks.

What is the exact error you get?
Hemoco
Lansweeper Alumni
Last boot time isn't stored in Lansweeper.