Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How do I get the Time since the computer started ?  (Read 6598 times)

0 Members and 1 Guest are viewing this topic.

ALAN_BR

    Topic Starter


    Hopeful

    Thanked: 5
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    How do I get the Time since the computer started ?
    « on: August 30, 2008, 09:16:13 AM »
    I believe Windows has a mSec counter timer which starts at zero upon system start-up,
    and I have a "System Resource" tool which includes displays of both normal time (hours, minutes etc.) and also the number of seconds since start-up, proving that what I want is in there somewhere.

    Is it possible (and how) for a batch file to also access this Windows timer ?

    n.b.  I tried Google, but every search I used either had more than a million hits with nothing relevant on the first page, or zero hits plus advice upon widening my search !!!

    Regards
    Alan

    Dias de verano

    • Guest
    Re: How do I get the Time since the computer started ?
    « Reply #1 on: August 30, 2008, 11:12:08 AM »
    Code: [Select]
    @echo off

    REM the next line gets the system uptime and converts it into a seconds figure
    REM and stores it in the variable %se%
    for /f "tokens=1-14 delims= " %%A in ('systeminfo ^| find "System Up Time"') do set /a se=86400*%%D+3600*%%F+60*%%H+%%J

    REM demonstrate use
    echo System uptime is %se% seconds

    ALAN_BR

      Topic Starter


      Hopeful

      Thanked: 5
      • Computer: Specs
      • Experience: Experienced
      • OS: Windows 7
      Re: How do I get the Time since the computer started ?
      « Reply #2 on: August 30, 2008, 01:16:04 PM »
      Sorry, it did not work, my fault.

      I quick search for "systeminfo" now shows me it needs XP Pro.

      I am amateur - Windows XP Home with SP3 - sorry I forgot to mention that.

      Is the any other way a batch command can extract this data from XP Home,
      or is the a small utility I can download as an interface between my batch and XP Home ?

      Regards
      Alan

      fireballs



        Apprentice

      • Code:Terminal
      • Thanked: 3
        Next time google it.

        Dias de verano

        • Guest
        Re: How do I get the Time since the computer started ?
        « Reply #4 on: August 30, 2008, 01:28:54 PM »
        This is the one you want. Save it somewhere on your PATH, for example c:\windows

        http://www.rickmaybury.com/Bootarc/toptips_files/systeminfo.exe

        « Last Edit: August 30, 2008, 01:41:02 PM by Dias de verano »

        drmsucks



          Specialist

          Re: How do I get the Time since the computer started ?
          « Reply #5 on: August 30, 2008, 01:30:39 PM »
          Or this: http://rbytes.net/software/uptime-review/

          You  can always look at event viewer to see when the current session started.
          If you don't have time to do it right
                          ...when will you have time to do it over?

          fireballs



            Apprentice

          • Code:Terminal
          • Thanked: 3
            Re: How do I get the Time since the computer started ?
            « Reply #6 on: August 30, 2008, 01:31:06 PM »
            you'd have to save the file into c:\windows\system32

            FB
            Next time google it.

            Dias de verano

            • Guest
            Re: How do I get the Time since the computer started ?
            « Reply #7 on: August 30, 2008, 01:35:02 PM »
            Or this: http://rbytes.net/software/uptime-review/

            You  can always look at event viewer to see when the current session started.

            Can it be used from a batch file to get the uptime into a variable, as the OP requested?

            Dias de verano

            • Guest
            Re: How do I get the Time since the computer started ?
            « Reply #8 on: August 30, 2008, 01:38:47 PM »
            try this: http://www.brothersoft.com/systeminfo-82007.html

            FB

            That is a GUI (Windows) app. The OP asked for a method usable from a batch file.

            ALAN_BR,

            This is the one you want. Save it somewhere on your PATH, for example c:\windows

            http://www.rickmaybury.com/Bootarc/toptips_files/systeminfo.exe

            drmsucks



              Specialist

              Re: How do I get the Time since the computer started ?
              « Reply #9 on: August 30, 2008, 01:57:17 PM »
              Or this: http://rbytes.net/software/uptime-review/

              You  can always look at event viewer to see when the current session started.

              Can it be used from a batch file to get the uptime into a variable, as the OP requested?

              I doubt it. I noted that the OP requested a batch file but he didn't state a purpose for knowing the uptime. All he said was, "Is it possible (and how) for a batch file to also access this Windows timer ?" If the purpose of the batch file was to answer the question, "How long has my system been up?" then, I think that this link will help. If the purpose of the batch file is to pass on the uptime, it won't.
              If you don't have time to do it right
                              ...when will you have time to do it over?

              Dias de verano

              • Guest
              Re: How do I get the Time since the computer started ?
              « Reply #10 on: August 30, 2008, 02:04:04 PM »
              Many people want a method of timing a process that does not involve using the %time% variable.

              ALAN_BR

                Topic Starter


                Hopeful

                Thanked: 5
                • Computer: Specs
                • Experience: Experienced
                • OS: Windows 7
                Re: How do I get the Time since the computer started ?
                « Reply #11 on: August 30, 2008, 02:09:25 PM »
                Thanks

                systeminfo is working for me now

                "System uptime is 21923 seconds
                Press any key to continue . . ."

                I have to go now - be back tomorrow.
                Thank you

                Regards
                Alan

                drmsucks



                  Specialist

                  Re: How do I get the Time since the computer started ?
                  « Reply #12 on: August 30, 2008, 02:14:42 PM »
                  Many people want a method of timing a process that does not involve using the %time% variable.
                  I know...and many people just want to know how long their system has been running. I cannot know for what purpose Alan wants to know the uptime. But based on this, it doesn't seem critical :)
                  Thanks

                  systeminfo is working for me now

                  "System uptime is 21923 seconds
                  Press any key to continue . . ."
                  If you don't have time to do it right
                                  ...when will you have time to do it over?

                  Dias de verano

                  • Guest
                  Re: How do I get the Time since the computer started ?
                  « Reply #13 on: August 30, 2008, 02:21:30 PM »
                  I cannot know for what purpose Alan wants to know the uptime. But based on this, it doesn't seem critical

                  That's a kind of snooty remark, isn't it? We have no way of knowing what Alan wants to do with a batch file. He has tried out a scheme for extracting uptime data from the output of systeminfo, with a simple script, and sounds satisfied that he can get it to work the way he wants. Who knows what code he will incorporate it in later?

                  drmsucks



                    Specialist

                    Re: How do I get the Time since the computer started ?
                    « Reply #14 on: August 30, 2008, 02:40:42 PM »
                    I cannot know for what purpose Alan wants to know the uptime. But based on this, it doesn't seem critical

                    That's a kind of snooty remark, isn't it? We have no way of knowing what Alan wants to do with a batch file. He has tried out a scheme for extracting uptime data from the output of systeminfo, with a simple script, and sounds satisfied that he can get it to work the way he wants. Who knows what code he will incorporate it in later?

                    Not meant to be a snooty remark - for the third time, I believe, I do not know for what purpose Alan wants to know uptime. From the subject of this thread and from his posted comments, I am convinced that he does want to know his system uptime; and, I offered a link to a software item that purports to answer the question. If the answer does not present itself in a form suitable for Alan's purpose, he is more than capable of disregarding it. If he perceives my previous post as "snooty," I will apologize to him.

                    If you don't have time to do it right
                                    ...when will you have time to do it over?