PDA

View Full Version : Batch file help



nofam
10-12-2008, 11:13 AM
I'm trying to figure out how to write a batch file that performs an action once a reply is received from a ping. The scenario is this:

2 laptops that connect wirelessly back to a server. The server's MoBo supports Wake on LAN, so I want a batch file that only sends the magic packet to the server's NIC once it senses that the laptops' wireless has connected. This turns on the server whenever either of the lappies connects, ensuring my files are available.

I'm currently using the following:


@echo off
ping -n 18 localhost
WOL.EXE [MAC address of servers' NIC here]


This does work, but it's a little clunky because it's just pinging itself for 18 seconds (effectively just a pause to fair for the wireless to connect) before calling the program.

Hope this makes sense!

:thumbs:

Speedy Gonzales
10-12-2008, 11:23 AM
Does this wol.exe command say it works with wireless??

Somehow I think it may only work with ethernet

How would WOL (this I would say, is usually for ethernet, not wireless), know you have wireless?

nofam
10-12-2008, 11:33 AM
LOL yeah you're right speedy :p

But it DOES work once the wireless connects - I've been using it with the batch file above for a few days now. . . .I just want a more elegant solution.

Speedy Gonzales
10-12-2008, 11:40 AM
Well if all 3 were connected with ethernet, and all 3 had options like WOL in the BIOS.

That would probably be the easiest way.

Once you turn one on, the other 2 will come on

Since they'll detect the LAN signal from each other

nofam
10-12-2008, 12:07 PM
That's what I'll do once I build my HTPC which will be hard-wired via Gigabit ethernet to the media server.

The batch file solution will do for now with the laptops.

Speedy Gonzales
10-12-2008, 12:13 PM
The server doesnt have wireless as well does it?

It would probably have to be onboard. If it did you could try bridging it and the LAN?

Isnt that what bridging does?

beama
10-12-2008, 12:50 PM
you might be able to modify this example

http://www.codingforums.com/archive/index.php/t-109430.html

MushHead
10-12-2008, 01:03 PM
You might want to check out what M$ has to say about the subject at MSDN (http://msdn.microsoft.com/en-us/library/aa394595(VS.85).aspx). There's got to be some useful info you can get via the WMI interface...

You can start a Windows script via cscript or wscript (GUI) at the command line.

dyewitness
10-12-2008, 01:05 PM
Maybe something like this:


@echo off

echo.
ping -n 5 %1

if errorlevel 1 (
goto wake-on-lan
)

echo.
echo Machine %1 already awake.
goto end

:wake-on-lan
echo.
echo Sending WOL packet to %1 (%2)
WOL.exe %2
goto end

:end



call it with:



whatever-you-call-the-bat-file [machine-host-name] [mac-address]
eg.
test-ping.bat myserver e2-b1-c3-d4

beama
10-12-2008, 01:21 PM
is that copyrighted dyewitness (please say no :lol:) cause I can see a use for it already and yes I tested it.

thank you

beama
10-12-2008, 01:25 PM
You might want to check out what M$ has to say about the subject at MSDN (http://msdn.microsoft.com/en-us/library/aa394595%28VS.85%29.aspx). There's got to be some useful info you can get via the WMI interface...

You can start a Windows script via cscript or wscript (GUI) at the command line.

and use shell(c:\mybatfile.bat) to run the batch file, Now I'm being silly. I agree scripting would give more flexibility

dyewitness
10-12-2008, 01:30 PM
is that copyrighted dyewitness (please say no :lol:) cause I can see a use for it already and yes I tested it.

thank you

Hehe, freeware, so modify and use as you wish.