Rawox Posted May 13, 2010 Posted May 13, 2010 (edited) Hi there, What's the best way to look (when a script runs) of it is the first run since Windows has started? Thanks in advance! Edited May 13, 2010 by Rawox
hawky358 Posted May 13, 2010 Posted May 13, 2010 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 ...
GEOSoft Posted May 13, 2010 Posted May 13, 2010 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!"
GEOSoft Posted May 13, 2010 Posted May 13, 2010 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!"
hawky358 Posted May 13, 2010 Posted May 13, 2010 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)?
Rawox Posted May 13, 2010 Author Posted May 13, 2010 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?
GEOSoft Posted May 13, 2010 Posted May 13, 2010 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!"
GEOSoft Posted May 13, 2010 Posted May 13, 2010 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 2My XPS 420 returnes 1/1/1980 12:00AMAlthough 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!"
hawky358 Posted May 13, 2010 Posted May 13, 2010 Hey GEOSoft Can you try net stats workstation ? Apparently it's a Vista issue (srv), but I'm not running Vista anywhere.
GEOSoft Posted May 13, 2010 Posted May 13, 2010 (edited) Hey GEOSoftCan 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 May 13, 2010 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!"
Rawox Posted May 13, 2010 Author Posted May 13, 2010 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...
hawky358 Posted May 13, 2010 Posted May 13, 2010 (edited) It should set @error, just check your consolebox if the boottime shows there. Edit: Consolebox [Not consolebox() ] Edited May 13, 2010 by hawky358
Rawox Posted May 13, 2010 Author Posted May 13, 2010 It sets @error and then exits because of If @error Then Exit
hawky358 Posted May 14, 2010 Posted May 14, 2010 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)
Rawox Posted May 14, 2010 Author Posted May 14, 2010 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
GEOSoft Posted May 14, 2010 Posted May 14, 2010 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!"
hawky358 Posted May 14, 2010 Posted May 14, 2010 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)
GEOSoft Posted May 14, 2010 Posted May 14, 2010 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!"
Rawox Posted May 16, 2010 Author Posted May 16, 2010 I am using SciTE and it doesn't return anything in the log window
GEOSoft Posted May 16, 2010 Posted May 16, 2010 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!"
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now