Jump to content

Get first run since boot


Recommended Posts

Hey

One method would be to have an ini/txt file (or even a registry entry) which logs what the boot time was when the script was last run.

ex. When you run the script, you check at what time the current Windows session started (Uptime), if this session is the same as the session in the log file/registry/whatever then it is not the first run.

Here's how you can get the time at which your PC booted into Windows. (Maybe there's a UDF or function in Autoit (Anyone know of it??)

#include <Constants.au3>
$out = Run("net stats srv","",@SW_hide,$STDOUT_CHILD)

local $output
While 1
    $output &= StdoutRead($out)
    If @error Then ExitLoop
Wend
    
$start = StringInStr($output,"Statistics since")
$end = StringInStr($output,@CR,-1,1,$start)
$boottime = StringMid($output,$start,$end-$start)
$boottime = StringReplace($boottime,"Statistics since ","")
ConsoleWrite($boottime) ;Write this boottime into ini/txt

I just made it a consolewrite so you can see what the output is ...

Link to comment
Share on other sites

Store the value of a variable in either an Ini file or the Windows Registry. Then set the variable the first time the script is run and reset it on Windows startup.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hey

One method would be to have an ini/txt file (or even a registry entry) which logs what the boot time was when the script was last run.

ex. When you run the script, you check at what time the current Windows session started (Uptime), if this session is the same as the session in the log file/registry/whatever then it is not the first run.

Here's how you can get the time at which your PC booted into Windows. (Maybe there's a UDF or function in Autoit (Anyone know of it??)

#include <Constants.au3>
$out = Run("net stats srv","",@SW_hide,$STDOUT_CHILD)

local $output
While 1
    $output &= StdoutRead($out)
    If @error Then ExitLoop
Wend
    
$start = StringInStr($output,"Statistics since")
$end = StringInStr($output,@CR,-1,1,$start)
$boottime = StringMid($output,$start,$end-$start)
$boottime = StringReplace($boottime,"Statistics since ","")
ConsoleWrite($boottime) ;Write this boottime into ini/txt

I just made it a consolewrite so you can see what the output is ...

Depending on the system, net stats will usually be a long way off on the date.

For example your code returns 1/1/1980 even on a system that is less than 2 years old.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Depending on the system, net stats will usually be a long way off on the date.

For example your code returns 1/1/1980 even on a system that is less than 2 years old.

Hmm interesting.

I've never seen it returning an incorrect date. What system was that on? (OS & SP)?

Link to comment
Share on other sites

Store the value of a variable in either an Ini file or the Windows Registry. Then set the variable the first time the script is run and reset it on Windows startup.

How can I reset it at startup?

Link to comment
Share on other sites

Just compile a script that resets it and put that in the startup folder

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hmm interesting.

I've never seen it returning an incorrect date. What system was that on? (OS & SP)?

Dell XPS 630 With Vista Ultimate 32 bit SP 2

My XPS 420 returnes 1/1/1980 12:00AM

Although it's much slower, a more accurate test is SystemInfo which will give you the last start date and time.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hey GEOSoft

Can you try net stats workstation ?

Apparently it's a Vista issue (srv), but I'm not running Vista anywhere.

It could well be just another Vista issue (I'm totally amazed). I will give it a try on my 420 when I boot into Win 7 and see what the difference is.

EDIT: Net stats workstation has the date correct on Vista. I'm not sure about the time though. It says I restarted the system an hour ago and I think I did a restart after that, could just be my memory again though.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Well. I tried some things but I can't get it to work.

I want it to be completely one script so no other executables that set registry entries etc.

When I try:

#include <Constants.au3>
$out = Run("net stats srv","",@SW_hide,$STDOUT_CHILD)

local $output
While 1
    $output &= StdoutRead($out)
    If @error Then Exit
Wend
    
$start = StringInStr($output,"Statistics since")
$end = StringInStr($output,@CR,-1,1,$start)
$boottime = StringMid($output,$start,$end-$start)
$boottime = StringReplace($boottime,"Statistics since ","")
ConsoleWrite($boottime) ;Write this boottime into ini/txt

It sets @error and exits...

Link to comment
Share on other sites

Oh I didn't see you changed the code there. It's supposed to be Exitloop. (You don't want to quit you just want out of the while loop)

The @error is supposed to be set, it reads everything once it reaches the end it sets @error. (since the net program closes after giving the output)

Link to comment
Share on other sites

Alright, changed it to this:

#include <Constants.au3>
$out = Run("net stats srv","",@SW_hide,$STDOUT_CHILD)

local $output
While 1
    $output &= StdoutRead($out)
    If @error Then ExitLoop
Wend
    
$start = StringInStr($output,"Statistics since")
$end = StringInStr($output,@CR,-1,1,$start)
$boottime = StringMid($output,$start,$end-$start)
$boottime = StringReplace($boottime,"Statistics since ","")
ConsoleWrite($boottime) ;Write this boottime into ini/txt

But it doesn't return anything :idea:

Link to comment
Share on other sites

Did you look at the console window at the bottom of Scite to see what it returned?. When ConsoleWrite becomes a pain in the arse (right about now) or if you are using an editor other than Scite just change the last line to a message box. You will find that much easier.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

When ConsoleWrite becomes a pain in the arse (right about now) or if you are using an editor other than Scite ...

Yea, I guess this is my bad, I like using consolewrite for debugging.

Like GEOSoft said just make it msgbox(0,"Time?",$boottime)

Link to comment
Share on other sites

Yea, I guess this is my bad, I like using consolewrite for debugging.

Like GEOSoft said just make it msgbox(0,"Time?",$boottime)

If you ever tried working with editors other than SciTe you might not like it so much. I don't even use it in SciTe. If I see consolewrite in any posted code I'll change it to a MsgBox before I test and that comes from years of not using SciTe as my primary editor. At least for now, I'm using SciTe (very customized) so it's not as irritating as it used to be.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Just on a hunch

Open a Cmd window and type

"net stats srv" (without the quotes)

Press Enter and see if that line exists for you or if you are even able to run it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...