jsteng Posted February 16, 2019 Posted February 16, 2019 Hi, I have been plagued by my wife and kids leaving the computer on overnight. No matter how many times I reprimand them, they still oftentimes forget to turn off the machine. And because all our files (My Document folder and Desktop) are stored on a NAS, Window's auto-hibernate does not work when MS Word/Excel has an open network file... THIS had gone for YEARS! So I happened to find some Autoit codes in this forum and combined some of them to make a Force Hibernate: expandcollapse popupOpt("TrayIconHide", 1) ; #FUNCTION#;=============================================================================== ; ; Name...........: _Timer_GetIdleTime() ; Description ...: Returns the number of ticks since last user activity (i.e. KYBD/Mouse) ; Syntax.........: _Timer_GetIdleTime() ; Parameters ....: None ; Return values .: Success - integer ticks since last (approx. milliseconds) since last activity ; Failure - Sets @extended = 1 if rollover occurs (see remarks) ; Author ........: PsaltyDS at http://www.autoitscript.com/forum ; Modified.......: v1.0.0 -- 03/20/2008 First version ; v1.0.1 -- 06/11/2008 Fixed bug when idle time = 0ms ; Remarks .......: The current ticks since last system restart will roll over to 0 every 50 days or so, ; which makes it possible for last user activity to be before the rollover, but run time ; of this function to be after the rollover. If this happens, @extended = 1 and the ; returned value is ticks since rollover occured. ; Related .......: _CheckIdle() ; Link ..........; ; Example .......; Yes ; ;;========================================================================================== Func _Timer_GetIdleTime() ; Get ticks at last activity Local $tStruct = DllStructCreate("uint;dword"); DllStructSetData($tStruct, 1, DllStructGetSize($tStruct)); DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($tStruct)) ; Get current ticks since last restart Local $avTicks = DllCall("Kernel32.dll", "int", "GetTickCount") ;Return time since last activity, in ticks (approx milliseconds) Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2) If $iDiff >= 0 Then ; Normal return Return $iDiff Else ; Rollover of ticks counter has occured Return SetError(0, 1, $avTicks[0]) EndIf EndFunc ;==>_Timer_GetIdleTime ;=============================================================================== ; ; Description: Sets a wakeup time to wake it up if the system / computer is hibernating or standby ; Parameter(s): $Hour - Hour Values : 0-23 ; $Minute - Minutes Values: 0-59 ; $Day - Days Values : 1-31 (optional) ; $Month - Month Values : 1-12 (optional) ; $Year - Year Values : > 0 (optional) ; ; Requirement(s): DllCall ; Return Value(s): On Success - 1 ; On Failure - 0 sets @ERROR = 1 and @EXTENDED (Windows API error code) ; ; Error code(s): [url=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes.asp]http://msdn.microsoft.com/library/default....error_codes.asp[/url] ; ; Author(s): Bastel123 aka Sebastian ; Note(s): - ; ;=============================================================================== Func _SetSuspend($mode=true,$force=true) $result = DllCall("PowrProf.dll", "long", "SetSuspendState", "long",$mode, "long",$force, "long", false) EndFunc GLOBAL $MaxIdleTime = 30 * 60 * 1000 local $idle = 0 Global $x = @DesktopWidth - 20 Global $y = @DesktopHeight - 10 func Print($text) ToolTip($text, $x, $y, "", 0, 2) endfunc While 1 if _Timer_GetIdleTime() > $MaxIdleTime then Print ("IDLE") _SetSuspend() while _Timer_GetIdleTime() > $MaxIdleTime sleep(1000) wend endif Print(stringformat("%0.0f", _Timer_GetIdleTime()/1000)) sleep(1000) wend So now, how do i make this script autorun everytime windows is loaded up? THanks!
FrancescoDiMuro Posted February 16, 2019 Posted February 16, 2019 @jsteng Use the startup folder Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
caramen Posted February 16, 2019 Posted February 16, 2019 You can use start up folder you can use planed task with task sheduler you can use registry My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
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