Jump to content
Sign in to follow this  
goss34

Logoff/Shutdown using system uptime

Recommended Posts

goss34

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

Share this post


Link to post
Share on other sites
guinness

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 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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
goss34

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

Share this post


Link to post
Share on other sites
goss34

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

Share this post


Link to post
Share on other sites
goss34

Fixed it by adding another if and looking for the response from the messagebox.

Cheers

Share this post


Link to post
Share on other sites
Exit

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()

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites
guinness

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 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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
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
Sign in to follow this  

×