Page 1 of 2

Batch Wake-On-Lan

Posted: 24 Dec 2013 04:59
by thephantomblu
Is there any way to implement WOL functionality in batch without the need of third-party software?

Re: Batch Wake-On-Lan

Posted: 24 Dec 2013 05:05
by ghostmachine4
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

Re: Batch Wake-On-Lan

Posted: 24 Dec 2013 05:13
by thephantomblu
No, you misunderstood me.

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

Re: Batch Wake-On-Lan

Posted: 24 Dec 2013 05:35
by ghostmachine4
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.

Re: Batch Wake-On-Lan

Posted: 24 Dec 2013 05:44
by thephantomblu
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!

Re: Batch Wake-On-Lan

Posted: 24 Dec 2013 06:31
by penpen
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

Re: Batch Wake-On-Lan

Posted: 24 Dec 2013 08:18
by thephantomblu
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?

Re: Batch Wake-On-Lan

Posted: 24 Dec 2013 09:16
by penpen
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.

Re: Batch Wake-On-Lan

Posted: 24 Dec 2013 14:21
by penpen

Re: Batch Wake-On-Lan

Posted: 24 Dec 2013 15:35
by Squashman
good to see there is a way to do it with Powershell.

Re: Batch Wake-On-Lan

Posted: 24 Dec 2013 22:43
by brianmadam
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.

Re: Batch Wake-On-Lan

Posted: 24 Dec 2013 23:17
by foxidrive
Here's a powershell solution that may work:

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

Re: Batch Wake-On-Lan

Posted: 25 Dec 2013 00:00
by thephantomblu
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!

Re: Batch Wake-On-Lan

Posted: 25 Dec 2013 00:05
by foxidrive
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.

Re: Batch Wake-On-Lan

Posted: 25 Dec 2013 00:11
by berserker
thephantomblu wrote:
penpen, can we call Powershell scripts in a batch file?


you can run powershell from batch. See here