Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Wake up Machine on LAN

Keywords:   wake up machine LAN


;Code to "Wake on LAN" (WOL)
;Debugged (more or less)



      #DefineFunction Hex2Dec(hex)
         str="0123456789ABCDEF"
         hex=StrTrim(StrUpper(hex))
         hexlen=StrLen(hex)
         dec=0
         for x=1 to hexlen
             dec=(dec*16) + StrIndex(str,strsub(hex,x,1),0,@fwdscan) -1
         next
         return(dec)
      #EndFunction





     BCastAddr="10.10.10.255"      ; Set network broacast address here
     MacAddress="11:22:33:44:55:66" ; Set MAC address of machine to wake up here

     ;--------------------------
     bbpacket=BinaryAlloc( (6*33) + 6)
     BinaryOLEType(bbpacket,101,0,0,0)

     BinaryPoke(bbpacket,0,255)
     BinaryPoke(bbpacket,1,255)
     BinaryPoke(bbpacket,2,255)
     BinaryPoke(bbpacket,3,255)
     BinaryPoke(bbpacket,4,255)
     BinaryPoke(bbpacket,5,255)


     For yy=0 to 32
         For xx=1 to 6
            mm=ItemExtract(xx,MacAddress,":")
            mm=Hex2Dec(mm)
            BinaryPoke(bbpacket,5+xx+(yy*6),mm)
         next
     next

;The WinSock OCX has a distribution problem in that
;it sometimes is not installed properly.  This is
;reported to fix it...


       if RegExistKey(@REGCLASSES,"Licenses\2c49f800-c2dd-11cf-9ad6-0080c7e7b78d") == @FALSE
          ErrorMode(@off)
          flag=RegSetValue(@REGCLASSES,"Licenses\2c49f800-c2dd-11cf-9ad6-0080c7e7b78d","mlrljgrlhltlngjlthrligklpkrhllglqlrk")
          ErrorMode(@cancel)
          if flag==0
             Message("Error","Admin access required to set registry key.")
             exit
          endif
       endif






     objSocket = ObjectOpen("MSWinsock.Winsock")
     objSocket.Protocol = 1     ;UDP
     objSocket.RemoteHost = BCastAddr
     objSocket.SendData(bbpacket)
     ObjectClose(objSocket)
     BinaryFree(bbpacket)

Message("All","Doned")
exit


Article ID:   W14632
Filename:   Wake up Machine on LAN.txt