Batch Wake-On-Lan

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
thephantomblu
Posts: 5
Joined: 24 Dec 2013 04:53

Batch Wake-On-Lan

#1 Post by thephantomblu » 24 Dec 2013 04:59

Is there any way to implement WOL functionality in batch without the need of third-party software?

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

Re: Batch Wake-On-Lan

#2 Post by ghostmachine4 » 24 Dec 2013 05:05

thephantomblu wrote:Is there any way to implement WOL functionality in batch without the need of third-party software?

you can do that with a vb script. I personally have not tried it but you can download the code here.

save it as something.vbs , edit the settings to your liking and execute

Code: Select all

c:\> cscript //nologo something.vbs

thephantomblu
Posts: 5
Joined: 24 Dec 2013 04:53

Re: Batch Wake-On-Lan

#3 Post by thephantomblu » 24 Dec 2013 05:13

No, you misunderstood me.

Is there any way you can send WOL packets through batch without third-party software?

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

Re: Batch Wake-On-Lan

#4 Post by ghostmachine4 » 24 Dec 2013 05:35

thephantomblu wrote:No, you misunderstood me.

Is there any way you can send WOL packets through batch without third-party software?


To send WOL packets programmatically you need the UDP protocol and for that you need to program using a language that support the UDP packet programming. If you really cannot use any other third party software (note, vbscript is installed by default and to me not considered third party), vbscript (or powershell) is your best bet. vbscript doesn't support sockets natively but you can call activex/com control ( Mswinsck.ocx etc ? Please research google for more) . if you have powershell on newer systems, you can make use of .Net libraries System.Net.Sockets API.

thephantomblu
Posts: 5
Joined: 24 Dec 2013 04:53

Re: Batch Wake-On-Lan

#5 Post by thephantomblu » 24 Dec 2013 05:44

ghostmachine4 wrote:To send WOL packets programmatically you need the UDP protocol and for that you need to program using a language that support the UDP packet programming. If you really cannot use any other third party software (note, vbscript is installed by default and to me not considered third party), vbscript (or powershell) is your best bet. vbscript doesn't support sockets natively but you can call activex/com control ( Mswinsck.ocx etc ? Please research google for more) . if you have powershell on newer systems, you can make use of .Net libraries System.Net.Sockets API.


Oh, okay. I will see if I can get anything about vbscript on Google. Thanks for the reply!

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch Wake-On-Lan

#6 Post by penpen » 24 Dec 2013 06:31

Maybe this is what you are searching for:
http://analects.jeffharbert.com/a-vbscript-wake-on-lan-project/.
(Especially the last script at the bottom of this page.)

penpen

thephantomblu
Posts: 5
Joined: 24 Dec 2013 04:53

Re: Batch Wake-On-Lan

#7 Post by thephantomblu » 24 Dec 2013 08:18

penpen wrote:Maybe this is what you are searching for:
http://analects.jeffharbert.com/a-vbscript-wake-on-lan-project/.
(Especially the last script at the bottom of this page.)

penpen


Code: Select all

Set objShell=CreateObject(“wscript.shell”)
strCommand=”C:\scripts\wol.exe” & strMAC
Set objExec=objShell.Exec(strCommand)


It uses an external application wol.exe. Any other ideas?

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch Wake-On-Lan

#8 Post by penpen » 24 Dec 2013 09:16

Sry, haven't inspected the source above fully (beside wol can be downloaded from http://www.gammadyne.com/cmdline.htm).

But maybe this may help you:
http://stackoverflow.com/questions/19508431/sending-magic-packet-with-vbs
(This should be a VB.NET source file, if i see it right.)

Additionally you may save this batch file as vbc.bat:

Code: Select all

:main
   @echo off
   setlocal
   cls

   set "vbc="

   pushd "%SystemRoot%\Microsoft.NET\Framework"
   for /f "tokens=* delims=" %%i in ('dir /b /o:n "v*"') do (
      dir /a-d /b "%%~fi\vbc.exe" >nul 2>&1 && set "vbc="%%~fi\vbc.exe""
   )
   popd

   if defined vbc (
      echo most recent VB.NET compiler located in:
      echo %vbc%.
   ) else (
      echo VB.NET compiler not found.
      goto :eof
   )

   %vbc% /nologo /target:exe /out:"%~f1.exe" "%~f1.vb"
   goto :eof
and compile the linked script using vbc.bat.

penpen

Edit: The .net framework has to be installed.

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch Wake-On-Lan

#9 Post by penpen » 24 Dec 2013 14:21


Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Batch Wake-On-Lan

#10 Post by Squashman » 24 Dec 2013 15:35

good to see there is a way to do it with Powershell.

brianmadam
Posts: 1
Joined: 24 Dec 2013 22:39

Re: Batch Wake-On-Lan

#11 Post by brianmadam » 24 Dec 2013 22:43

thephantomblu wrote:Is there any way to implement WOL functionality in batch without the need of third-party software?

what system are you running on? If its newer version, check if you have powershell installed.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch Wake-On-Lan

#12 Post by foxidrive » 24 Dec 2013 23:17

Here's a powershell solution that may work:

http://gallery.technet.microsoft.com/sc ... n-815424c4

thephantomblu
Posts: 5
Joined: 24 Dec 2013 04:53

Re: Batch Wake-On-Lan

#13 Post by thephantomblu » 25 Dec 2013 00:00

So I think there is absolutely NO way to do this in native batch.



penpen, can we call Powershell scripts in a batch file?

foxidrive wrote:Here's a powershell solution that may work:

http://gallery.technet.microsoft.com/sc ... n-815424c4


Thanks. This code looks cleaner!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch Wake-On-Lan

#14 Post by foxidrive » 25 Dec 2013 00:05

thephantomblu wrote:can we call Powershell scripts in a batch file?


You can, though there can be issues with permissions and the default restrictions in Powershell.

berserker
Posts: 95
Joined: 18 Dec 2013 00:51

Re: Batch Wake-On-Lan

#15 Post by berserker » 25 Dec 2013 00:11

thephantomblu wrote:
penpen, can we call Powershell scripts in a batch file?


you can run powershell from batch. See here

Post Reply