Member_2_6492660_1
asked on
BGINFO Shutdown Reason
I run a script everytime my Windows 2003 Servers start that run bginfo and puts the information on the desktop.
Works great on Windows 2003 and Windows 2008 Servers.
I would like to add a field to the display to show the reason for the last shutdown.
Example I had a Power outage today and my UPS's units keep the servers up but shutdown after a long outage. The all shutdown normally except for one. When that one came back online it presented me with a reason for shutdown screen where I entered trouble number and description.
Would like that info to be displayed using bginfo.
Any one have a script that can do this?
Works great on Windows 2003 and Windows 2008 Servers.
I would like to add a field to the display to show the reason for the last shutdown.
Example I had a Power outage today and my UPS's units keep the servers up but shutdown after a long outage. The all shutdown normally except for one. When that one came back online it presented me with a reason for shutdown screen where I entered trouble number and description.
Would like that info to be displayed using bginfo.
Any one have a script that can do this?
It'll be a bit tricky, so you'll have to fiddle a bit. Info from last shutdown is stored in the event log, so you'll have to set up a Custom field to display the event log info. To do that, press Custom... and select WMI Query. Try using Win32_NTLogEvent, that'll get you access to the event log. From there, you'll have to isolate what you want to show (and not show), which I would recommend experimenting with until you get what you want (depending on your preference as to too much or too little).
ASKER
Hi thanks for the input
Was hoping for a script to do this
Anyone have an example of a script?
Was hoping for a script to do this
Anyone have an example of a script?
Create a custom variable in BGInfo and attach to it the following VBScript:
An see if will return the expected result.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Security)}!\\" & _
strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent " _
& "Where LogFile='System' and SourceName='user32'")
For Each objLogFile In colLogFiles
Echo objLogFile.Message
Exit For
Next
An see if will return the expected result.
ASKER
I ran this
C:\Temp>cscript test.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Temp\test.vbs(9, 5) Microsoft VBScript runtime error: Type mismatch: 'Echo'
also should we refine this to the event messages 1076 and 1074 if so how?
C:\Temp>cscript test.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Temp\test.vbs(9, 5) Microsoft VBScript runtime error: Type mismatch: 'Echo'
also should we refine this to the event messages 1076 and 1074 if so how?
To see the results when running with cscript you shoud modify the line:
Echo objLogFile.Message
to display:
Wscript.Echo objLogFile.Message
But shoud remain simply echo when running in BGInfo.
To include both event codes use the following script:
Echo objLogFile.Message
to display:
Wscript.Echo objLogFile.Message
But shoud remain simply echo when running in BGInfo.
To include both event codes use the following script:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Security)}!\\" & _
strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent " _
& "Where LogFile='System' and SourceName='user32' and (EventCode='1074' or EventCode='1076')")
For Each objLogFile In colLogFiles
wscript.Echo objLogFile.Message
Exit For
Next
ASKER
Luconsta
Thanks that works great.
Is there anyway to only display
Reason Code
Shutdown Type
Comment
Really do not need the description field
see below
Here is the event 1074
Log Name: System
Source: USER32
Date: 7/12/2013 1:41:42 PM
Event ID: 1074
Task Category: None
Level: Information
Keywords: Classic
User: PC01\Test
Computer: TB-07182012
Description:
The process C:\Windows\system32\winlog on.exe (PC01) has initiated the restart of computer PC01 on behalf of user PC01\Test for the following reason: No title for this reason could be found
Reason Code: 0x500ff
Shutdown Type: restart
Comment:
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="USER32" />
<EventID Qualifiers="32768">1074</E ventID>
<Level>4</Level>
<Task>0</Task>
<Keywords>0x80000000000000 </Keywords >
<TimeCreated SystemTime="2013-07-12T17: 41:42.0000 00000Z" />
<EventRecordID>80923</Even tRecordID>
<Channel>System</Channel>
<Computer>PC01\Test</Compu ter>
<Security UserID="S-1-5-21-232777447 0-48006329 7-23634014 49-1000" />
</System>
<EventData>
<Data>C:\Windows\system32\ winlogon.e xe (PC01\Test)</Data>
<Data>PC01\Test</Data>
<Data>No title for this reason could be found</Data>
<Data>0x500ff</Data>
<Data>restart</Data>
<Data>
</Data>
<Data>PC01\Test</Data>
<Binary>FF0005000000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 00</Binary >
</EventData>
</Event>
Thanks that works great.
Is there anyway to only display
Reason Code
Shutdown Type
Comment
Really do not need the description field
see below
Here is the event 1074
Log Name: System
Source: USER32
Date: 7/12/2013 1:41:42 PM
Event ID: 1074
Task Category: None
Level: Information
Keywords: Classic
User: PC01\Test
Computer: TB-07182012
Description:
The process C:\Windows\system32\winlog
Reason Code: 0x500ff
Shutdown Type: restart
Comment:
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="USER32" />
<EventID Qualifiers="32768">1074</E
<Level>4</Level>
<Task>0</Task>
<Keywords>0x80000000000000
<TimeCreated SystemTime="2013-07-12T17:
<EventRecordID>80923</Even
<Channel>System</Channel>
<Computer>PC01\Test</Compu
<Security UserID="S-1-5-21-232777447
</System>
<EventData>
<Data>C:\Windows\system32\
<Data>PC01\Test</Data>
<Data>No title for this reason could be found</Data>
<Data>0x500ff</Data>
<Data>restart</Data>
<Data>
</Data>
<Data>PC01\Test</Data>
<Binary>FF0005000000000000
</EventData>
</Event>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Script works great thanks
ASKER
luconsta
can you look at this one for me?
It is part of this one but I created another question for it
https://www.experts-exchange.com/questions/28189036/VBS-Script-help-needed.html
Thanks
can you look at this one for me?
It is part of this one but I created another question for it
https://www.experts-exchange.com/questions/28189036/VBS-Script-help-needed.html
Thanks