Jump to content
Sign in to follow this  
joehittn

Wake on Lan Skript

Recommended Posts

joehittn

my attempt:

i wanted to make a gui button to run a function, which contains another funciton...

; Arbeitsvariablen
Global $i

; Variablen - Workstationbezeichnungen (IPs)
#include <Array.au3>
Global $CompArray[26]
$CompArray[1] = "r15"
.....


; Variablen - MAC-Adressen
#include <Array.au3>
Global $MacArray[26]
$MacArray[1] = "00:04:76:8E:41:2D"
.....


GUI-stuff...

GUICtrlSetOnEvent($Button1, "Wakeup_all_schleife")



; Functions
Func Wakeup_all_schleife ()
for $i = 1 to 2
    Wakeup_all ()
Next
Exit
EndFunc


Func Wakeup_all ()
    sleep (500)
    send ("#r", 0)
    sleep (500)
    send ("cmd", 0)
    sleep (500)
    send ("{enter}")    
    sleep (500)
    send("Z:")
    send ("{enter}")
    send("cd Z:\temp\aktuelles\")
    sleep (500)
    send ("{enter}")
    send ("wolcmd " & $MacArray[$i] & " " & $CompArray[$i] & " 255.255.255.0 80", 1)
    send ("{enter}")
    sleep (2000)
    WinClose("Untitled - Notepad", "")
EndFunc

i guess its a problem with the $i variable used in the for-loop, which cant be used afterwards in the function, but aehm, i dont know why that is and how i could get around this...

thnx in advance,

joehittn

Share this post


Link to post
Share on other sites
PsaltyDS

The For keyword automatically declares a local variable, I believe, so the For/Next is working with the local $i but your second function is using the global one. Just dump the global and pass the variable as a parameter:

; Functions
Func Wakeup_all_schleife ()
    for $i = 1 to 2
        Wakeup_all ($i)
    Next
    Exit
EndFunc

Func Wakeup_all ($n)

    ; ...

    send ("wolcmd " & $MacArray[$n] & " " & $CompArray[$n] & " 255.255.255.0 80", 1)
    send ("{enter}")
    sleep (2000)
    WinClose("Untitled - Notepad", "")
EndFunc

You don't have to rename the variable from $i to $n in the second function, I just did it to enphasize what was being done.

: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

Share this post


Link to post
Share on other sites
Nahuel

Well of course... you could do something like this:

Func Wakeup_all_schleife ()
for $i = 1 to 2
    Wakeup_all ($i)
Next
Exit
EndFunc


Func Wakeup_all ($a)
    sleep (500)
    send ("#r", 0)
    sleep (500)
    send ("cmd", 0)
    sleep (500)
    send ("{enter}")    
    sleep (500)
    send("Z:")
    send ("{enter}")
    send("cd Z:\temp\aktuelles\")
    sleep (500)
    send ("{enter}")
    send ("wolcmd " & $MacArray[$a] & " " & $CompArray[$a] & " 255.255.255.0 80", 1)
    send ("{enter}")
    sleep (2000)
    WinClose("Untitled - Notepad", "")
EndFunc

-edit-

Listen to the penguin!

Edited by Nahuel

Share this post


Link to post
Share on other sites
joehittn

thanks a lot to the animals of the sea or lake or antarctica!! :-)

works fine now!

cheers

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.