goss34 Posted July 13, 2011 Share Posted July 13, 2011 Hi Guys, I am looking for a way to be able to have a timer or something running that can monitor the system uptime on a machine and when it reaches for example 18 hours it will prompt the user (if logged on) that the machine will shutdown in for example 30 minutes. I have found a script that works using the mouse position then i could run the shutdown but that is in effect an idle timer on the system so wouldnt work in the scenario i want. Heres the script if that helps: AdlibRegister("_UpdateTimer", 100) Global $nTimer = 0 Global $OldMousePosition = MouseGetPos() GLobal $NewMousePosition While(1) sleep(10) WEnd Func _UpdateTimer() $nTimer += 100 ;100 ms $NewMousePosition = MouseGetPos() if (($NewMousePosition[0] == $OldMousePosition[0]) and ($NewMousePosition[1] == $OldMousePosition[1])) Then ; The user is still idle (you might also want to check for key presses Else ; The user moved, we should start the timer over. $OldMousePosition = $NewMousePosition $nTimer = 0 EndIf if ($nTimer >= 5000) Then ;Change the '5000' to the number in milliseconds you want to wait, with your user being idle. _OnTimerFinish() $nTimer = 0 EndIf EndFunc Func _OnTimerFinish() MsgBox(0, "", "idle hands are the devil's tools") AdlibUnRegister() Exit EndFunc Can someone help or at least point me in the right direction to use the "system uptime" clock? Thank you, Dan Link to comment Share on other sites More sharing options...
guinness Posted July 13, 2011 Share Posted July 13, 2011 (edited) Have a look at _WinAPI_GetTickCount() in WinAPIEx.au3 to retrieve how long the machine has been running. Retrieves the number of milliseconds that have elapsed since the system was started. Example use: If _WinAPI_GetTickCount() > 64800000 Then ; Shutdown. EndIf Edited July 13, 2011 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
water Posted July 13, 2011 Share Posted July 13, 2011 Did you use the forum search function? When I search for "system uptime" the second entry is an UDF which does what you need. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
goss34 Posted July 13, 2011 Author Share Posted July 13, 2011 Thanks Guiness, Hadnt come accross that before, will experiment with it but it looks like that will work providing i can write the rest of the code Cheers Dan Have a look at _WinAPI_GetTickCount() in WinAPIEx.au3 to retrieve how long the machine has been running. Example use: If _WinAPI_GetTickCount() > 64800000 Then ; Shutdown. EndIf Link to comment Share on other sites More sharing options...
goss34 Posted July 13, 2011 Author Share Posted July 13, 2011 Can you make a message box have no buttons? (Ok, Cancel) I am using a message box with a timeout of 10 minutes then another with 5 then the system restarts, the problem is if the user clicks ok to the messages it reboots straight away! I tried using sleep but then the user doesnt see a message. I use the message first then the sleep i end up waiting for 20 minutes. Any ideas? Thanks Dan Link to comment Share on other sites More sharing options...
goss34 Posted July 13, 2011 Author Share Posted July 13, 2011 Fixed it by adding another if and looking for the response from the messagebox. Cheers Link to comment Share on other sites More sharing options...
Exit Posted July 13, 2011 Share Posted July 13, 2011 For such purposes, I use splash. Here a sample:$handle = SplashTextOn("Messages","Here is my first message" , 900, 200, -1, -1, 16 + 32, "", 50, 900) Sleep(3000) WinSetState($handle, "", @SW_HIDE) Sleep(3000) ControlSetText($handle, "", "Static1", "Here is my second message", 1) WinSetState($handle, "", @SW_SHOW) Sleep(3000) WinSetState($handle, "", @SW_HIDE) ControlSetText($handle, "", "Static1", "Here is last message", 1) WinSetState($handle, "", @SW_SHOW) Sleep(3000) SplashOff() App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
guinness Posted July 13, 2011 Share Posted July 13, 2011 (edited) Or using GUICreate() #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> _Main() Func _Main() Local $iHeight = 300, $iWidth = 400 GUICreate("Blank MsgBox()", $iWidth, $iHeight, -1, -1, $DS_MODALFRAME) GUICtrlCreateLabel("Something is happening...", 5, 5, $iWidth - 15, $iHeight - 35) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc ;==>_Main Edited July 13, 2011 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
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