Sign in to follow this  
Followers 0
GrahamT

Program used to work OK

1 post in this topic

#1 ·  Posted (edited)

I just dug out a program I wrote two years ago (using some ideas I found online), which used to work fine, to make some modifications to it. Its for controlling workstations in the computer lab at my school.

I've recompiled it, with no changes, in the latest version of AutoIt.

It used to work fine - now I get an error 1063 when I run it. What does this mean? I've tried running it normally, from the command line, as a service - same every time.

Also, after the error message, I get the confirmation dialog, that the workstation is listening on port 31313, but when I try to ping the workstation it says the port is not open. I realise the dialog is not actually checking - its just reporting what is supposed to happen! Any ideas why it isn't working?

Thanks.

#include <service.au3>
_Service_Init("LRCstudent_Service")
TCPStartup(); Start up the TCP functions
#NoTrayIcon; Hide the tray icon... so students don't know its running!

$ipAddress = @IPAddress1
$portAddress = 31313
$MainSocket = TCPListen($ipAddress, $portAddress)
MsgBox(4096, "Lab Remote Control", "Listening on IP: " & $ipAddress & " and PORT: " & $portAddress, 5)

Func Main()
While 1
    Do
        $ConnectedSocket = TCPAccept($MainSocket)
    Until $ConnectedSocket > 0
    
    $err = 0
    Do
        $msg = TCPRecv($ConnectedSocket, 512)
        $err = @error
        If StringLen($msg) Then
; go through the various messages to process them accordingly...
            If StringInStr($msg, "WINDOWSHAKE:") Then
                windowShake()
            ElseIf StringInStr($msg, "SCREENFLICKER:") Then
                screenFlicker()
            ElseIf StringInStr($msg, "SCREENBLANK:") Then
                screenToggle(1, 2)
            ElseIf StringInStr($msg, "SCREENRESTORE:") Then
                screenToggle(0, -1)
            ElseIf StringInStr($msg, "ALERTBOX:") Then
                Send("{SPACE}")
                $alertBoxText = StringReplace($msg, "ALERTBOX:", "")
                MsgBox(48, "", $alertBoxText, 10)
            ElseIf StringInStr($msg, "SHUTDOWN:") Then
                Shutdown(5)
            ElseIf StringInStr($msg, "REBOOT:") Then
                Shutdown(6)
            ElseIf StringInStr($msg, "LOGOFF:") Then
                Shutdown(4)
            ElseIf StringInStr($msg, "EXIT:") Then
                goAway()
            EndIf
            
        EndIf
        
    Until $err
    TCPCloseSocket($ConnectedSocket)
WEnd
EndFunc
; End of the main loop

; ----------------------------------------------------------------------
Func goAway()
    TCPShutdown()
    Exit
EndFunc;==>goAway

; ----------------------------------------------------------------------
Func windowShake()
; Script to shake the current window...
    $windowArray = WinList()
    
; Set up some of the shake parameters
    $numShakes = 30
    $shakeIntensity = 10
    $shakeDelay = 20
    
    For $i = 1 To $windowArray[0][0]
; Loop through to find the active window... and shake it...
        If $windowArray[$i][0] <> "" And isVisible($windowArray[$i][1]) And WinActive($windowArray[$i][0]) Then
            $posArray = WinGetPos($windowArray[$i][0])
; Shake it!
            For $x = 1 To $numShakes
                If Random(0, 1) = 1 Then $shakeIntensity = $shakeIntensity * - 1
                WinMove($windowArray[$i][0], "", $posArray[0] + $shakeIntensity, $posArray[1] + $shakeIntensity)
                Sleep(10)
                WinMove($windowArray[$i][0], "", $posArray[0], $posArray[1])
            Next
        EndIf
    Next
EndFunc;==>windowShake

; ----------------------------------------------------------------------
Func screenFlicker()
    Opt("WinTitleMatchMode", 4)
    $WM_SYSCommand = 274
    $SC_MonitorPower = 61808
    $Power_On = -1
    $Power_Off = 2
;$X = 1
    $HWND = WinGetHandle("classname=Progman")
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND, "int", $WM_SYSCommand, "int", $SC_MonitorPower, "int", $Power_Off)
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND, "int", $WM_SYSCommand, "int", $SC_MonitorPower, "int", $Power_On)
EndFunc;==>screenFlicker

; ----------------------------------------------------------------------
Func screenToggle($keyb, $change)
    Opt("WinTitleMatchMode", 4)
    $WM_SYSCommand = 274
    $SC_MonitorPower = 61808
    $HWND = WinGetHandle("classname=Progman")
    BlockInput($keyb)
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND, "int", $WM_SYSCommand, "int", $SC_MonitorPower, "int", $change)
EndFunc;==>screenToggle

; ----------------------------------------------------------------------
Func isVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc;==>isVisible
Edited by GrahamT

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  
Followers 0