Jump to content

Recommended Posts

Posted (edited)

I was really bored and created a script that will open three things on my left monitor at logon of any user.

I started by adding a Scheduled Task with Task Scheduler.

General: Run with Highest Privileges 
Trigger: At Log On
Action: Start a Program (My compiled WinPos Script)

I know it's convoluted, I just had too much spare time so I went into error checking too much.

Here's a screenshot.

image.thumb.png.de490b077c50e9913c87da5b70b0a19b.png

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Misc.au3>
Opt("WinTextMatchMode", 2)

Local $TaskMgr[4]
$TaskMgr[0] = "-1927,0,958,1047"             ; Window Position
$TaskMgr[1] = "Task Manager"                ; Window Title
$TaskMgr[2] = @SystemDir & "\Taskmgr.exe"    ; Binary Location
$TaskMgr[3] = ""                            ; Arguments

Local $Ping[4]
$Ping[0] = "-986,0,989,1044"                ; Window Position
$Ping[1] = @SystemDir & "\PING.EXE"            ; Window Title
$Ping[2] = @SystemDir & "\PING.EXE"            ; Binary Location
$Ping[3] = " -t 1.1.1.1"                    ; Arguments

Local $ThrottleStop[4]
$ThrottleStop[0] = "-572, 394, 574,487"                                ; Window Position
$ThrottleStop[1] = "ThrottleStop 9.7.3 - Monitoring"                ; Window Title
$ThrottleStop[2] = "E:\Apps\ThrottleStop_9.7.3\ThrottleStop.exe"    ; Binary Location
$ThrottleStop[3] = ""                                                ; Arguments

Local $hDLL

_Handle($TaskMgr)
_Handle($Ping)
_Handle($ThrottleStop)

_WaitForExit()

Func _WaitForExit()
    $hDLL = DllOpen("User32.dll")
    _Debug("MAIN: Press Return to Exit...")
    While 1
        If _IsPressed($VK_RETURN, $hDLL) And WinActive(@ScriptFullPath) Then
            Exit
        EndIf
        Sleep(250)
    WEnd
EndFunc

Func _Handle($pArray)
    If IsArray($pArray) Then
        _Debug("_Handle(): $pArray is an Array.")
    Else
        _Error("_Handle(): $pArray is NOT an Array!")
        Return SetError(1, 0, False)
    EndIf
    If UBound($pArray) = 4 Then
        _Debug("_Handle(): $pArray is proper size.")
    Else
        _Error("_Handle(): $pArray is WRONG size!")
        Return SetError(2, 0, False)
    EndIf

    Local $lPos = StringSplit($pArray[0], ",")
    If IsArray($lPos) Then
        _Debug("_Handle(): $lPos is an Array!")
    Else
        _Error("_Handle(): $lPos is NOT an Array!")
        Return SetError(3, 0, False)
    EndIf
    If UBound($lPos) = 5 Then
        _Debug("_Handle(): $lPos is proper size.")
    Else
        _Error("_Handle(): $lPos is WRONG size!")
        Return SetError(4, 0, False)
    EndIf

    Local $lTitle = $pArray[1]
    If $lTitle <> "" Then
        _Debug("_Handle(): $lTitle: " & $lTitle)
    Else
        _Error("_Handle(): $lTitle cannot be blank!")
        Return SetError(5, 0, False)
    EndIf

    Local $lBinaryLocation = $pArray[2]
    If $lBinaryLocation <> "" Then
        _Debug("_Handle(): $lBinaryLocation: " & $lBinaryLocation)
    Else
        _Error("_Handle(): $lBinaryLocation cannot be blank!")
        Return SetError(6, 0, False)
    EndIf
    If FileExists($lBinaryLocation) Then
        _Debug("_Handle(): $lBinaryLocation file exists.")
    Else
        _Error("_Handle(): $lBinaryLocation file does NOT exist!")
        Return SetError(7, 0, False)
    EndIf

    Local $lArguments = $pArray[3]
    If $lArguments <> "" Then
        _Debug("_Handle(): $lArguments = " & $lArguments)
    Else
        _Debug("_Handle(): No $lArguments.")
    EndIf
    If WinExists($lTitle) Then
        _Debug("_Handle(): " & $lTitle & " already running!")
    Else
        ShellExecute($lBinaryLocation, $lArguments, @SystemDir)
        If Not @error Then
            _Debug("_Handle(): Executed $lBinaryLocation successfully.")
        Else
            _Error("_Handle(): FAILED to execute $lBinaryLocation!")
            Return SetError(8, 0, False)
        EndIf
    EndIf
    
    _Debug("_Handle(): Waiting for window to appear (30s)...")
    If WinWait($lTitle, "", 30) Then
        _Debug("_Handle(): Window appeared.")
    Else
        _Error("_Handle(): Timed out waiting for window to appear!")
        Return SetError(9, 0, False)
    EndIf
    If WinMove($lTitle, "", $lPos[1], $lPos[2], $lPos[3], $lPos[4]) Then
        _Debug("_Handle(): Moved window successfully.")
    Else
        _Error("_Handle(): Failed to move window!")
        Return SetError(10, 0, False)
    EndIf
    Return True
EndFunc   ;==>_Handle

Func _Debug($pData)
    ConsoleWrite($pData & @CRLF)
EndFunc   ;==>_Debug

Func _Error($pData)
    ConsoleWrite($pData & @CRLF)
    ConsoleWrite(">> ERROR DETECTED <<" & @CRLF & @CRLF)
EndFunc   ;==>_Error

 

Simplified Version:

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Misc.au3>
Opt("WinTextMatchMode", 2)

Local $TaskMgr[4]
$TaskMgr[0] = "-1927,0,958,1047"             ; Window Position
$TaskMgr[1] = "Task Manager"                ; Window Title
$TaskMgr[2] = @SystemDir & "\Taskmgr.exe"    ; Binary Location
$TaskMgr[3] = ""                            ; Arguments

Local $Ping[4]
$Ping[0] = "-986,0,989,1044"                ; Window Position
$Ping[1] = @SystemDir & "\PING.EXE"            ; Window Title
$Ping[2] = @SystemDir & "\PING.EXE"            ; Binary Location
$Ping[3] = " -t 1.1.1.1"                    ; Arguments

Local $ThrottleStop[4]
$ThrottleStop[0] = "-572, 394, 574,487"                                ; Window Position
$ThrottleStop[1] = "ThrottleStop 9.7.3 - Monitoring"                ; Window Title
$ThrottleStop[2] = "E:\Apps\ThrottleStop_9.7.3\ThrottleStop.exe"    ; Binary Location
$ThrottleStop[3] = ""                                                ; Arguments

_Handle($TaskMgr)
_Handle($Ping)
_Handle($ThrottleStop)

Func _Handle($pArray)
    Local $lPos = StringSplit($pArray[0], ",")
    Local $lTitle = $pArray[1]
    Local $lBinaryLocation = $pArray[2]
    Local $lArguments = $pArray[3]
    ShellExecute($lBinaryLocation, $lArguments, @SystemDir)
    WinWait($lTitle, "")
    WinMove($lTitle, "", $lPos[1], $lPos[2], $lPos[3], $lPos[4]) Then
EndFunc   ;==>_Handle

 

Edited by BinaryBrother

SIGNATURE_0X800007D NOT FOUND

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
×
×
  • Create New...