Jump to content

Basic script that won't work in practice


 Share

Recommended Posts

Basically, it monitoring the tasklist for .scr and then shutdowns the

computer if the screensaver been active for

more than 10 min. But it wont work in practice.

Any idea why?

#NoTrayIcon

RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Run", "Auto Shutdown")
If @Error = -1 Then
RegWrite('HKCU\Software\Microsoft\Windows\CurrentVersion\Run' , 'Auto Shutdown', 'REG_SZ', '"' & @ScriptFullPath & '"')
EndIf

Func isScreensaverOn()
   ; 1 = on , 0 = off
    Local $list = ProcessList()
    For $i = 1 To $list[0][0]
        If StringInStr($list[$i][0], ".scr") Then Return 1
    Next
    Return 0
EndFunc  ;==>isScreensaverOn

$i = 0
Do
$Screensaver = isScreensaverOn()
    If $Screensaver = 1 Then
        sleep(2500)                   
        $i = $i + 1
    Else
        $i = 0
    EndIf
sleep(1000)
Until $i = 240

Shutdown(9)
Link to comment
Share on other sites

Basically, it monitoring the tasklist for .scr and then shutdowns the

computer if the screensaver been active for

more than 10 min. But it wont work in practice.

Any idea why?

#NoTrayIcon

RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Run", "Auto Shutdown")
If @Error = -1 Then
RegWrite('HKCU\Software\Microsoft\Windows\CurrentVersion\Run' , 'Auto Shutdown', 'REG_SZ', '"' & @ScriptFullPath & '"')
EndIf

Func isScreensaverOn()
   ; 1 = on , 0 = off
    Local $list = ProcessList()
    For $i = 1 To $list[0][0]
        If StringInStr($list[$i][0], ".scr") Then Return 1
    Next
    Return 0
EndFunc  ;==>isScreensaverOn

$i = 0
Do
$Screensaver = isScreensaverOn()
    If $Screensaver = 1 Then
        sleep(2500)                   
        $i = $i + 1
    Else
        $i = 0
    EndIf
sleep(1000)
Until $i = 240

Shutdown(9)
Because when you run "ABCD.src" it appears in the process list as "ABCD.exe".

EDIT: Crossed out reply which was wrong.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Because when you run "ABCD.src" it appears in the process list as "ABCD.exe".

I don't think so. Set your screensaver waiting time to 1 min, and you will see

that it will work. It think the problem is that the monitor shutsdown or

the "login window" activates.

#NoTrayIcon

RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Run", "Auto Shutdown")
If @Error = -1 Then
RegWrite('HKCU\Software\Microsoft\Windows\CurrentVersion\Run' , 'Auto Shutdown', 'REG_SZ', '"' & @ScriptFullPath & '"')
EndIf

Func isScreensaverOn()
   ; 1 = on , 0 = off
    Local $list = ProcessList()
    For $i = 1 To $list[0][0]
        If StringInStr($list[$i][0], ".scr") Then Return 1
    Next
    Return 0
EndFunc  ;==>isScreensaverOn

$i = 0
Do
$Screensaver = isScreensaverOn()
    If $Screensaver = 1 Then
        sleep(2500)                   
        $i = $i + 1
    Else
        $i = 0
    EndIf
sleep(1000)
Until $i = 2

msgbox(0,"","It worked!")
Link to comment
Share on other sites

I don't think so. Set your screensaver waiting time to 1 min, and you will see

that it will work. It think the problem is that the monitor shutsdown or

the "login window" activates.

#NoTrayIcon

RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Run", "Auto Shutdown")
If @Error = -1 Then
RegWrite('HKCU\Software\Microsoft\Windows\CurrentVersion\Run' , 'Auto Shutdown', 'REG_SZ', '"' & @ScriptFullPath & '"')
EndIf

Func isScreensaverOn()
   ; 1 = on , 0 = off
    Local $list = ProcessList()
    For $i = 1 To $list[0][0]
        If StringInStr($list[$i][0], ".scr") Then Return 1
    Next
    Return 0
EndFunc  ;==>isScreensaverOn

$i = 0
Do
$Screensaver = isScreensaverOn()
    If $Screensaver = 1 Then
        sleep(2500)                   
        $i = $i + 1
    Else
        $i = 0
    EndIf
sleep(1000)
Until $i = 2

msgbox(0,"","It worked!")
OK, then maybe I'm wrong. I tried my test again and I see that I ran the wrong thing. Apologies; I don't have an answer.

But if yu think it's the monitor shutting down why not increase the delay fo rthe monitor shut down to 15 minutes?

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

OK, then maybe I'm wrong. I tried my test again and I see that I ran the wrong thing. Apologies; I don't have an answer.

But if yu think it's the monitor shutting down why not increase the delay fo rthe monitor shut down to 15 minutes?

Thanks for your replay!

I will play around with it tomorrow, any other method to detect if the computer is inactive?

Edit: Found what I'm been looking for.

Dim $last_active = 0
Dim $timer = TimerInit()

While (1)
    $not_idle = _CheckIdle($last_active)
    If $not_idle <> 0 Then $timer = TimerInit()
    ToolTip(Int(TimerDiff($timer)/1000))
    Sleep(200)
WEnd

Func _CheckIdle(ByRef $last_active, $start = 0)
    $struct = DllStructCreate("uint;dword");
    DllStructSetData($struct, 1, DllStructGetSize($struct));
    If $start Then
        DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))
        $last_active = DllStructGetData($struct, 2)
        Return $last_active
    Else
        DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))
        If $last_active <> DllStructGetData($struct, 2) Then
            Local $save = $last_active
            $last_active = DllStructGetData($struct, 2)
            Return $last_active - $save
        EndIf
    EndIf
EndFunc;==>_CheckIdle

Func _Terminate()
    Exit
EndFunc;==>_Terminated
Edited by walle
Link to comment
Share on other sites

Thanks for your replay!

I will play around with it tomorrow, any other method to detect if the computer is inactive?

You have to define "inactive" very carefully. Do you mean time since last user mouse/keyboard action? Then _Timer_GetIdleTime() would work.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...