Jump to content

Remote Management Script scenario


ioa747
 Share

Recommended Posts

ReMagment.au3   Remote Management Script scenario

On the remote computer the script ReMagment.au3 is running, and  watching a specific shared folder e.g WatchFolder

If  specific text file exists then execute the file name and delete the text file

I make a text file with name _Make_this().order   without ending .txt
and I copy it to the WatchFolder
in the  remote computer execute the Func  _Make_this() and then delete the _Make_this().order  file

all executable orders must have the suffix .order

e.g  _RunNotepad().order
e.g  _ShellExecute(@MyDocumentsDir).order
e.g  GoToExit().order
e.g  _Make_that().order

and last Special.order  is a special order
I make a AutoIT script and I rename it to Special.order and I copy it to the WatchFolder

then the remote script will get it, will rename it to  Special.order.au3  it will execute it, and then it will delete it

ReMagment.au3

; https: https://www.autoitscript.com/forum/topic/210068-remote-management-script-scenario/
;----------------------------------------------------------------------------------------
; Title...........: ReMagment.au3
; Description.....: Remote Management Script
; AutoIt Version..: 3.3.16.1   Author: ioa747
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <WinAPIFiles.au3>

;*************************************  ;this script run in a remote mashine and watching in a specific
Global $WatchDir = "\\PC\WatchFolder\"  ;shared folder  e.g in WatchFolder  * <-
;*************************************  ;if file exist with 'something.order' format then Execute it

WatchFolder()

;----------------------------------------------------------------------------------------
Func GoToExit() ; exit
    Exit
EndFunc   ;==>GoToExit
;----------------------------------------------------------------------------------------
Func WatchFolder()

    While 1
        FindOrderFile()

        Sleep(3000)
    WEnd

EndFunc   ;==>WatchFolder
;----------------------------------------------------------------------------------------
Func FindOrderFile()
    Local $ArraySrtfiles = _FileListToArrayRec($WatchDir, "*.order", $FLTAR_FILES)
    If Not IsArray($ArraySrtfiles) Then
        ;ConsoleWrite($WatchDir & " = Invalid input path" & @CRLF)
        Return
    Else
        For $x = 1 To $ArraySrtfiles[0]
            ;ConsoleWrite($WatchDir & $ArraySrtfiles[$x]& @CRLF)
            ExecuteOrder($ArraySrtfiles[$x])
        Next
    EndIf
EndFunc   ;==>FindOrderFile
;----------------------------------------------------------------------------------------
Func ExecuteOrder($OrderFile)

    Local $sOrder

    ;check if $OrderFile exist
    If FileExists($WatchDir & $OrderFile) Then
        If $OrderFile = "Special.order" Then
            ConsoleWrite("-- Execute:Special.order" & @CRLF)
            SpecialOrder($OrderFile)
        Else
            $sOrder = StringSplit($OrderFile, ".")

            ;check if something.order format exist
            If $sOrder[0] = 2 And $sOrder[2] = "order" Then
                Local $iDel = FileDelete($WatchDir & $OrderFile) ;$OrderFile Delete
                ConsoleWrite("FileDelete:" & $iDel & @CRLF)
                ConsoleWrite("-- Execute:" & $sOrder[1] & @CRLF)
                Execute($sOrder[1])
            EndIf
        EndIf
    EndIf

EndFunc   ;==>ExecuteOrder
;----------------------------------------------------------------------------------------
Func SpecialOrder($OrderFile)

    ; Create a constant variable in Local scope of the filepaths that will be renamed.
    Local Const $sSource = $WatchDir & $OrderFile, _
            $sDestination = $WatchDir & $OrderFile & ".au3"

    ; Rename a file using FileMove and overwrite the new file if it exists.
    FileMove($sSource, $sDestination, $FC_OVERWRITE)

    ; Display results that the destination file was renamed.
    RunWait(FileGetShortName(@AutoItExe) & " " & FileGetShortName($sDestination)) ;& " " & $Param)

    ; Delete the temporary files. FileDelete checks if the file exists.
    FileDelete($sSource)
    FileDelete($sDestination)
EndFunc   ;==>SpecialOrder
;----------------------------------------------------------------------------------------
Func _RunNotepad()
    ; Run Notepad
    Run("notepad.exe")

    ; Wait 10 seconds for the Notepad window to appear.
    WinWait("[CLASS:Notepad]", "", 10)

    ; Test if the window exists and display the results.
    If WinExists("[CLASS:Notepad]") Then
        MsgBox($MB_SYSTEMMODAL, "", "Window exists", 5)
    Else
        MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Window does not exist", 5)
    EndIf

    ; Close the Notepad window.
    WinClose("[CLASS:Notepad]", "")
EndFunc   ;==>_RunNotepad
;----------------------------------------------------------------------------------------
Func _Make_this()
    MsgBox($MB_SYSTEMMODAL, "Make_this", "ExecuteOrderFile OK", 5)
EndFunc   ;==>_Make_this
;----------------------------------------------------------------------------------------
Func _Make_that()
    MsgBox($MB_SYSTEMMODAL, "Make_that", "ExecuteOrderFile OK", 5)
EndFunc   ;==>_Make_that
;----------------------------------------------------------------------------------------

Please, leave your comments and experiences here 

Thanks !

:)

Edited by ioa747

I know that I know nothing

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...