Announcement

Collapse
No announcement yet.

Last Reboot Time !

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Last Reboot Time !

    Does anyone knows the registry key to get the last reboot time in Windows XP Pro ?

    Thanks in advance

  • #2
    Re: Last Reboot Time !

    its not exactly reboot time, more like uptime
    have a read

    start > run > CMD
    net statistics workstation
    and its not a registry key (does it have to be?)
    "...if I turn out to be particularly clear, you've probably misunderstood what I've said” - Alan Greenspan

    Comment


    • #3
      Re: Last Reboot Time !

      In XP:
      Code:
      systeminfo | find "Up Time"
      In Vista:
      Code:
      C:\Users\Andrew>systeminfo | find "System Boot Time"
      System Boot Time:          7/13/2007, 2:37:13 PM
      Code:
      C:\Users\Andrew>net statistics workstation | find "Statistics"
      Workstation Statistics for \\A5541TAG-WKS
      Statistics since 7/13/2007 2:37:57 PM
      This is a little more accurate. Net statistics uses the time that the workstation service started. On my machine [Vista] there's over a 30 second difference.
      Last edited by ahinson; 16th July 2007, 18:46.
      Andrew

      ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

      Comment


      • #4
        Re: Last Reboot Time !

        samdazz how you want to use the information?

        Want to use it as a variable in a Batch:
        Code:
        @echo off
        :// Give the name of the target computer
        Set strComputer=ComputerName
        
        for /f "Tokens=2 Delims==" %%i in ('wmic /node:%strComputer% OS Get LastBootUpTime /format:list') Do Set LastBootUpTime=%%i
        Set LBT-Year=%LastBootUpTime:~0,4%||:   yyy
        Set LBT-Month=%LastBootUpTime:~4,2%||:   mm
        Set LBT-Day=%LastBootUpTime:~6,2%||:     dd
        Set LBT-Hour=%LastBootUpTime:~8,2%||:    hh
        Set LBT-Minute=%LastBootUpTime:~10,2%||: mm
        Set LBT-Second=%LastBootUpTime:~12,2%||: ss
        cls
        
        @echo.
        @echo %strComputer%
        @echo Last Boot Date= %LBT-Month%/%LBT-Day%/%LBT-Year% (mm/dd/yyyy)
        @echo Last Boot Time= %LBT-Hour%^:%LBT-Minute%^:%LBT-Second%
        
        @echo.
        @pause
        Or in a VBScript?
        Code:
        '// Give the name of the target computer
        strComputer = "ComputerName"
        Set objWMIService = GetObject("winmgmts:\\" _
            & strComputer & "\root\cimv2")
        Set colOperatingSystems = objWMIService.ExecQuery _
            ("Select * from Win32_OperatingSystem")
         
        For Each objOS in colOperatingSystems
            dtmBootup = objOS.LastBootUpTime
            Exit For
        Next
        
        WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
                Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) )
        WMIDateStringToTime = CDate(Mid(dtmBootup, 9, 2) & ":" & _
                Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2))
        
        Wscript.Echo strComputer & vbNewLine & _
                            "Last Boot Date= " & WMIDateStringToDate & vbNewLine & _
                            "Last Boot Time= " & WMIDateStringToTime
        \Rems
        Last edited by Rems; 16th July 2007, 20:53. Reason: add the posibility to use the scripts against emote computers

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: Last Reboot Time !

          I just want to see the user's machine remotely so that I can check the reboot time or uptime. Lot of our users are not rebooting their machines on Friday nights, so we need to check it manually. Basically I was looking for some registry key, but this info will also work.
          Thanks for all your responses.

          Comment


          • #6
            Re: Last Reboot Time !

            AHINSON: Please write the command for a specific remote machine:

            { C:\net statistics workstation | find "Statistics" Workstation Statistics for \\DTworkstation006 } doesn't work.

            Comment


            • #7
              Re: Last Reboot Time !

              You can now use both script (batch and vbs in my post) also for targetting remote computers.

              Replace Computername with the name of the target computer.

              (note: don't use quotes and spaces in the batch (.bat-file) around the computername. But in the vbscript (vbs-file), you must use quotes)

              \Rems




              - - - - - - - - - - - - - - - - - - - -
              Edit -

              If you prefere to use one command-line, try this:
              Start | Run: cmd /k wmic /node:ComputerName os get LastBootUpTime,CSName /format:list

              You get the BootTime in this format: yyyymmddhhmmss.****Bias

              For more output information, type the command below:
              cmd /k wmic os Get /?
              You can add the properties from the list at the command-line after Get (separate them with a comma).

              - - - - - - - - - - - - - - - - - - - -
              or: Howto Determine Windows Uptime: (tip!!)
              http://forums.petri.com/showthread.php?t=13933
              uptime.exe /s ComputerName
              (for usage information, type: uptime.exe /help)
              .
              Last edited by Rems; 17th July 2007, 11:24.

              This posting is provided "AS IS" with no warranties, and confers no rights.

              __________________

              ** Remember to give credit where credit's due **
              and leave Reputation Points for meaningful posts

              Comment


              • #8
                Re: Last Reboot Time !

                Where should I put the remote machine name in the script? Is it possible with any of these scripts to check on a remote machine for its Boot time or Up time?
                Thanks

                Comment


                • #9
                  Re: Last Reboot Time !

                  You mean my script? replace the text: ComputerName with the name of the remote computer.


                  But do checkout the last part of the "EDIT" in my last post,
                  download the tool 'Uptime.exe' to your computer : http://www.microsoft.com/downloads/d...displaylang=en

                  use the toole like this:
                  Uptime.exe /s ComputerName

                  This wil give a complete information about the logoff-times and startup-times during the last month of the target computer, including the current Uptime.

                  \Rems

                  This posting is provided "AS IS" with no warranties, and confers no rights.

                  __________________

                  ** Remember to give credit where credit's due **
                  and leave Reputation Points for meaningful posts

                  Comment


                  • #10
                    Re: Last Reboot Time !

                    Instead of checking to see if the computers were restarted, why not just schedule them to be restarted?

                    It could done by running a scheduled task from the server.

                    Assuming we're dealing with an Active Directory environment, this script will restart all computers in the Domain.com\Corp\Workstations OU and its child OUs if any.

                    Code:
                    On Error Resume Next
                    
                    Set objConnection = CreateObject("ADODB.Connection")
                    objConnection.Open "Provider=ADsDSOObject;"
                    
                    Set objCommand = CreateObject("ADODB.Command")
                    objCommand.ActiveConnection = objConnection
                    
                    
                    '--- change the DN to where you want to start your search ---
                    objCommand.CommandText = _
                        "<LDAP://ou=workstations,ou=corp,dc=domain,dc=com>;" & _
                            "(objectCategory=computer);distinguishedName,name;subtree"
                     
                    Set objRecordSet = objCommand.Execute
                    
                    While Not objRecordSet.EOF
                    
                        RestartComputer objRecordSet.Fields("Name")
                        objRecordSet.MoveNext
                    
                    Wend
                    
                    objConnection.Close
                    
                    
                    Sub RestartComputer(strComputer)
                    
                        set objShell = CreateObject("WScript.Shell") 
                        objShell.Run "shutdown -s -t 0 -f -m \\" & strComputer
                    
                    End Sub
                    You may need a more complex LDAP query if your workstations are in different branches of the hierarchy or if there's computers you don't want to restart in the OU(s).

                    Rems and Andrew, I'm sure you can improve on this script.
                    Regards,
                    Jeremy

                    Network Consultant/Engineer
                    Baltimore - Washington area and beyond
                    www.gma-cpa.com

                    Comment


                    • #11
                      Re: Last Reboot Time !

                      Jeremy W :::: Should this script be placed is a .vbs file and run it using the scheduled task on the server that is running AD, or there is a way we can put this in GPO? Please be specific and show how to do this, if possible attach some pictures of How to do it.
                      Thanks

                      Comment


                      • #12
                        Re: Last Reboot Time !

                        Originally posted by samdazz View Post
                        Should this script be placed is a .vbs file and run it using the scheduled task on the server that is running AD, or there is a way we can put this in GPO? Please be specific and show how to do this, if possible attach some pictures of How to do it.
                        Thanks
                        Oh, very demanding, eh?

                        1. Yes, it should be placed in a text file with a .vbs extension.
                        2. You can run it from any computer that has the shutdown.exe utility (XP & 2003) using administrative credentials.
                        3. GPO is not suitable for this script. Scheduled Tasks is the way to go.

                        I recommend running it from a server at a time when nobody will be using the computers and when it won't interfere with other processes (like backups and virus scans)

                        To set up the scheduled task:
                        -Save the code to a .vbs file in a convenient location (like C:\Scripts)
                        -Create the scheduled task. I found this neat article that has pictures! http://www.iopus.com/guides/winscheduler.htm For step 2 in the article, browse to the vbs file you saved.


                        Here's an updated script that will only restart computers running XP or 2000 Pro and it will now use the default naming context so it can be run without modification. You can, however, easily narrow the search by editing the strContainer variable.

                        Code:
                        On Error Resume Next
                        
                        '* Enter the DN of the container you want to base your 
                        '* search in excluding the domain name (dc=domain,dc=com)
                        '* between the double quotes below. If you want it to
                        '* search the root leave it blank.
                        
                        strContainer = "" 
                        
                        Set objRootDSE = GetObject("LDAP://rootDSE")
                        
                        If strContainer = "" Then
                            strADsPath = objRootDSE.Get("defaultNamingContext")
                        Else
                            strADsPath = strContainer & "," & objRootDSE.Get("defaultNamingContext")
                        End If
                        
                        Set objConnection = CreateObject("ADODB.Connection")
                        objConnection.Open "Provider=ADsDSOObject;"
                        
                        Set objCommand = CreateObject("ADODB.Command")
                        objCommand.ActiveConnection = objConnection
                        
                        
                         
                        objCommand.CommandText = _
                            "<LDAP://" & strADsPath & ">;" & _
                                "(&(objectCategory=computer)(|(operatingSystem=Windows XP*)(operatingSystem=Windows 2000 P*)))" & _
                                ";distinguishedName,name;subtree"
                         
                        Set objRecordSet = objCommand.Execute
                        
                        While Not objRecordSet.EOF
                        
                            RestartComputer objRecordSet.Fields("Name")
                            objRecordSet.MoveNext
                        
                        Wend
                        
                        objConnection.Close
                        
                        
                        Sub RestartComputer(strComputer)
                        
                            set objShell = CreateObject("WScript.Shell") 
                            objShell.Run "shutdown -s -t 0 -f -m \\" & strComputer
                        
                        End Sub
                        Last edited by JeremyW; 24th July 2007, 15:01. Reason: took out an unnecessary comment in script
                        Regards,
                        Jeremy

                        Network Consultant/Engineer
                        Baltimore - Washington area and beyond
                        www.gma-cpa.com

                        Comment

                        Working...
                        X