Jump to content

want to start remote process on 30 comp simultaneously


amfony
 Share

Recommended Posts

hay hay,

I want to be able to turn off monitors to approx 30 computers simultaneously. I can achieve this in a way (not simultaneous) by writing a batch script 'for' loop and using psexec to run a local file that achieves what i want. (File is nircmd.exe -- very handy!).

What happens now it that monitors turn off in sequence - not simultaneous.

I dont like to ask for answers alot, which i seem to be doing here in this forum. So can anyone tell me how i would achieve what i want, and ill look up functions and piece it together myself.

Im not a coder by profession only by neccesity so im not sure how i can achieve this - as in should i create a file to start 30 intances of psexec? should i create a service (or agent) on every computer and some how send signal (to invoke) to computers?

Thanks for any info guys and gals!

Link to comment
Share on other sites

maybe it wasnt clear to you -

i was looking for advice on what 'model' to use to acheive what i want. Not for coding help.

Perhaps if there was a 'What model should i use' forum then ofcourse, id leave my message there. Since there isnt, this seems to be it.

Do feel free to leave constructive help however.

Thanks for reading though. Peace.

Link to comment
Share on other sites

hay hay,

I want to be able to turn off monitors to approx 30 computers simultaneously. I can achieve this in a way (not simultaneous) by writing a batch script 'for' loop and using psexec to run a local file that achieves what i want. (File is nircmd.exe -- very handy!).

What happens now it that monitors turn off in sequence - not simultaneous.

I dont like to ask for answers alot, which i seem to be doing here in this forum. So can anyone tell me how i would achieve what i want, and ill look up functions and piece it together myself.

Im not a coder by profession only by neccesity so im not sure how i can achieve this - as in should i create a file to start 30 intances of psexec? should i create a service (or agent) on every computer and some how send signal (to invoke) to computers?

Thanks for any info guys and gals!

I don't think you can get the "command" to all of them simultaneously. The next thing to do would be sending it to each in turn, but modify the command to trigger at a common time, say at time = @MIN + 2.

I used to use psexec a lot for all kinds of legitimate admin functions, but keep in mind that anything it sends, including passwords if you are authenticating from the commandline, are passed in plain text. There are better ways where security is a concern.

:P

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

Is this a "do it once" task or do you want to do it every day?

If they have to be turned off at the same time you should write a script to be executed at a certan time. Run the upload script some 35 minutes upfront and wait for the magic to append. You will find scripts to turn of the monitor in the Scripts & Scraps forum. How to use psexecute with AutoIt is in the forum somewhere (probably in suport).

If it is a daily task (or several times a day? classrom? ) You could implement a service and a simple protocol to order "monitor off" from a master machine.

Link to comment
Share on other sites

I'd create a small remote control program. You have the server on your computer, and the others are the clients. Check out the "TCP made easy" or whatever, there are a client and a server there. Let the clients check for messages, one can for example be "shutdown". Then you just let your server send those messages. Got it?

EDIT: I started on a script for you. It is kind of messy, because i modified my own remote commander to fit your needs. The Server goes on your computer, the client on the others. You might have to edit some things.

EDIT 2: I forgot...

Use ~ as prefix for commands, eg ~shutdown

% as prefix causes the text to be sent to the clients' keyboards!

No prefix means code is evaluated and returned, so sending "@WindowsDir" will return ALL CLIENTS' WINDOWS DIR, each in a new msgbox, so be careful with this one.

Server

#NoTrayIcon
#Include <Constants.au3>

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)

If @Compiled == 0 Then
    TraySetIcon("Shell32.dll",2)
    
    TrayCreateItem("Send Command")
    TrayItemSetOnEvent(-1, "SendCommand")
    
    TrayCreateItem("Exit")
    TrayItemSetOnEvent(-1, "Terminate")
    TraySetState()
EndIf

Const $PORT = 8000
Const $LISTEN_IP = @IpAddress1

Global $MaxConc = 100

Global $MainSocket = TCPStartServer($PORT, $MaxConc)

If @error <> 0 Then
    If @Compiled == 0 Then MsgBox(16, "Error", "Server unable to initialize.")
    Exit
EndIf

Const $MaxLength = 2048

Global $ConnectedSocket[$MaxConc]
Global $CurrentSocket = 0
Local $Track = 0
Const $MAX_CONNECTION = ($MaxConc - 1)

For $Track = 0 To $MAX_CONNECTION Step 1
    $ConnectedSocket[$Track] = -1
Next

While 1
    $ConnectedSocket[$CurrentSocket] = TCPAccept($MainSocket)
    If $ConnectedSocket[$CurrentSocket] <> - 1 Then
        $CurrentSocket = SocketSearch()
    EndIf
    $Track = 0
    For $Track = 0 To $MAX_CONNECTION Step 1
        If $ConnectedSocket[$Track] <> - 1 Then
            $Data = TCPRecv($ConnectedSocket[$Track], $MaxLength)
            If $Data <> "" Then
                Cmd($Data)
            EndIf
        EndIf
    Next
WEnd

;##################################

Func SendCommand()
    $x = InputBox("Remote Command", "Command to be sent")
    If $x <> "" Then
        TCPSendMessageAll($MAX_CONNECTION, $x)
    EndIf
EndFunc

;##################################

Func Cmd($Data)
    If StringLeft($Data, 1) == "~" Then
        $cmd = StringMid($Data, 2)
        $param = ""
        If StringInStr($Data, "//") Then
            $cmd = StringSplit($cmd, "//", 1)
            $param = $cmd[2]
            $cmd = $cmd[1]
        EndIf
        Switch($cmd)
            Case "bye"
                TCPCloseSocket($ConnectedSocket[$Track])
                $ConnectedSocket[$Track] = -1
                $CurrentSocket = SocketSearch()
        EndSwitch
    Else
        MsgBox(0, "Data recieved", $Data)
    EndIf
EndFunc

;##################################

Func SocketSearch()
    Local $Track = 0
    For $Track = 0 To $MAX_CONNECTION Step 1
        If $ConnectedSocket[$Track] = -1 Then
            Return $Track
        Else
        EndIf
    Next
EndFunc

Func TCPSendMessageAll($ConnectionLimit, $Data)
    Local $Track = 0
    For $Track = 0 To $ConnectionLimit Step 1
        If $ConnectedSocket[$Track] <> - 1 Then TCPSend($ConnectedSocket[$Track], $Data)
    Next
EndFunc

Func TCPStartServer($PORT, $MaxConnect = 1)
    Local $Socket
    $Socket = TCPStartup()
    Select
        Case $Socket = 0
            SetError(@error)
            Return -1
    EndSelect
    $Socket = TCPListen(TCPNameToIp($LISTEN_IP), $PORT, $MaxConnect)
    Select
        Case $Socket = -1
            SetError(@error)
            Return 0
    EndSelect
    SetError(0)
    Return $Socket
EndFunc

Func Terminate()
    Exit 0
EndFunc
Edited by Persen
Link to comment
Share on other sites

good point confuzzled, but wouldnt it be a trough not spike? (equally as bad) I will need to address this point when i implment my solution.

Thanks for all the replys guys. Am busy this weekend with uni work but i will get knee deep into this in the coming week.

The TCP stuff looks intersting and the server/client idea seems to be exsactly what i am looking for. So thank you all for both the 'model' help and the code examples. I will try to achieve what i want - if i able to to complete it i will return with the code.

Thanks again ch'all.

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