Re: 2 questions: uptime and last logged on users

From: Sameh Ahmed (essoplus_at_hotmail.com)
Date: 05/04/04


Date: Tue, 4 May 2004 11:58:57 +0200

Thanks guys.
Win32_PerfFormattedData_PerfOS_System is not the best idea for me as most of
my babies are W2k.
As for the last logged on users, not all my clients have auditing enabled.
and if I use the profiles it will be easy to delete them.
I was wondering if any class has them stored among it's properties?
Regards
Sameh

"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:%23d8Kd7VMEHA.1388@TK2MSFTNGP09.phx.gbl...
> Sameh Ahmed wrote:
>
> > Hello there
> > Anybody where to look for the computer uptime, and where to look for a
list
> > of accounts that logged on to the system previously?
> Hi
>
> To see who has logged on previously, you could enumerate the locally
> stored profiles on a computer, take a look at the script in this link:
>
>
http://groups.google.com/groups?selm=O6LMjgtLEHA.2736%40TK2MSFTNGP11.phx.gbl
>
>
> For your computer uptime question:
>
> Note: "Win32_PerfFormattedData_PerfOS_System" mentioned by Jiachuan
> Wang is for WinXP and above only.
>
> Here is a script that works for Win2k (and NT4 if WMI is installed)
> as well:
>
>
> strComputer = "." ' "." for local computer
>
> On Error Resume Next
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer _
> & "\root\cimv2")
>
> If Err.Number = 0 Then
> On Error Goto 0
> Set colOperatingSystems = objWMIService.ExecQuery _
> ("Select * from Win32_OperatingSystem")
>
> For Each objOS in colOperatingSystems
> dtmLastBootUpTime = ConvWMIDateTime(objOS.LastBootUpTime,
"ISO8601")
> dtmSystemUptimeInHours = DateDiff("h", dtmLastBootUpTime, Now)
> dtmSystemUptimeInDays = DateDiff("d", dtmLastBootUpTime, Now)
> Wscript.Echo "Computer: " & strComputer _
> & " started at " & dtmLastBootUpTime
> Wscript.Echo "Uptime in hours: " & dtmSystemUptimeInHours
> Wscript.Echo "Uptime in days: " & dtmSystemUptimeInDays & vbCrlf
> Next
>
> Else
> Wscript.Echo "Could not connect to computer with WMI: " _
> & strComputer
> End If
>
>
> Function ConvWMIDateTime(sDMTFformat, iNamedFormat)
>
> ' Author: Torgeir Bakken
> ' Modified: 2004-01-16
> '
> ' Converts WMI Date and Time Format to standard date/time
> '
> ' WMI Date and Time Format is documented here:
> '
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/date_and_time_format.asp
> '
> ' Arguments ----->
>
> ' DMTFformat: Date string in WMI Date and Time Format
> '
> ' iNamedFormat: Optional. Numeric value that indicates the date/time
> ' format used. If omitted, ISO 8601 is used.
>
> ' -1 (and anything <> 0-4) Display in International Date Format ISO8601
> ' YYYY-MM-DD hh:nn:ss e.g. 2004-01-15 23:50:44
> '
> ' vbGeneralDate 0 Display a date and/or time. If there is a date part,
> ' display it as a short date. If there is a time part,
> ' display it as a long time. If present, both parts are
> ' displayed.
> '
> ' vbLongDate 1 Display a date using the long date format specified in
> ' your computer's regional settings.
> '
> ' vbShortDate 2 Display a date using the short date format specified in
> ' your computer's regional settings.
> '
> ' vbLongTime 3 Display a time using the time format specified in your
> ' computer's regional settings.
> '
> ' vbShortTime 4 Display a time using the 24-hour format (hh:mm).
>
> Dim sYear, sMonth, sDay, sHour, sMinutes, sSeconds
> sYear = mid(sDMTFformat, 1, 4)
> sMonth = mid(sDMTFformat, 5, 2)
> sDay = mid(sDMTFformat, 7, 2)
> sHour = mid(sDMTFformat, 9, 2)
> sMinutes = mid(sDMTFformat, 11, 2)
> sSeconds = mid(sDMTFformat, 13, 2)
>
> ' YYYY-MM-DD hh:nn:ss
> ConvWMIDateTime = sYear & "-" & sMonth & "-" & sDay & " " _
> & sHour & ":" & sMinutes & ":" & sSeconds
>
> If IsNumeric(iNamedFormat) Then
> If iNamedFormat >= 0 And iNamedFormat <= 4 Then
> ' FormatDateTime will set date format to specified format
> ConvWMIDateTime = FormatDateTime(ConvWMIDateTime, iNamedFormat)
> End If
> End If
> End Function
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/community/scriptcenter/default.mspx



Relevant Pages

  • Re: 2 questions: uptime and last logged on users
    ... > Anybody where to look for the computer uptime, and where to look for a list ... ' Converts WMI Date and Time Format to standard date/time ... ' vbGeneralDate 0 Display a date and/or time. ...
    (microsoft.public.win32.programmer.wmi)
  • Re: Up time stats?
    ... ' Converts WMI Date and Time Format to standard date/time ... ' vbGeneralDate 0 Display a date and/or time. ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.win2000.general)
  • Re: Up time stats?
    ... I would use WMI to pull the information. ... > On Error Goto 0 ... > ' Converts WMI Date and Time Format to standard date/time ... > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.win2000.general)
  • Re: WMI Reference
    ... You will be writing a complex custom application / script for that. ... A good way to get used to what Wmi is and the way it works is to use ... be detected by Sms, etc. ... Scriptomatic tool from the scripting tech center. ...
    (microsoft.public.sms.admin)
  • Re: security center
    ... but you can query the PC's via WMI (Windows Management Instrumentation) scripting. ... The below script is for the local computer, and would need to be modified to determine all PC's on your network/domain and then query each computer individually and report when there is a problem. ...
    (microsoft.public.windowsxp.security_admin)