After you install UltraWOL, you can access its properties, methods, and events, which the Ultrajones Software Web site lists. However, when I use a new OCX, I'm always extra careful that I'm using it correctly. So, to explore the OCX's contents, I opened the Object Browser in Microsoft Word 2002 by selecting Tools, Macro, Visual Basic Editor, then pressing F2. (Previous versions of Word might not have F2 support. If pressing F2 doesn't work, you can open the Object Browser from the View menu.) UltraWOL wasn't in the list of available objects to browse, so I added a reference by selecting References on the Tools menu, clicking Browse, finding and highlighting ultrawol.ocx, then clicking Open. Figure 1 shows the References dialog box after I added the OCX reference.
With UltraWOL now in the list of available objects, I selected that object and explored its properties, methods, and events. As Figure 2 shows, the object has four properties (BroadcastAddr, LocalIP, MACAddr, and Version), one method (WakeUp), and two events (WOLComplete and WOLError). The Object Browser not only lists an object's properties, methods, and events but also tells you how to use them. Highlighting a property, method, or event prompts the Object Browser to display the syntax in the status bar at the bottom of the window, as Figure 2 shows.
Using the Scripts
Listing 2, page 12, contains SendMagicPacket.vbs, a modified version of one of the scripts that Ultrajones Software provides. This script creates an instance of the UltraWOL object, then uses the BroadcastAddr, MAC-Addr, and LocalIP properties to identify the target PC to wake up. Finally, the script uses the WakeUp method to send a magic packet to that target PC.
To use SendMagicPacket.vbs, you need to customize the lines that callout A in Listing 2 shows. You set the BroadcastAddr property to the broadcast address of the subnet that the target PC is on. Typically, the broadcast address is x.y.z.255, where x.y.z is the first three IP segments of the PC's IP address. You set the MACAddr property to your NIC's media access control (MAC) address. The MAC address must be in six hexadecimal segments separated by hyphens, as the second line at callout A shows. You can obtain the MAC address with the Windows OS tool msinfo.exe or msinfo32.exe, depending on the PC's OS. Some PCs have more than one NIC. For example, home PCs that connect to a cable modem and to a home network might have two NICs. When a PC has multiple cards, you need to target a specific card when you wake up the PC. To do so, you set the LocalIP property to the IP address of the NIC you want to target. If you don't have multiple NICs in the target PC, you need to remove or comment out the last line at callout A in Listing 2.
Listing 3 contains the script SendMagicPacketWithEvents.vbs, a modified version of another script that Ultrajones Software provides. Because it uses events, SendMagicPacketWithEvents.vbs is more advanced than SendMagicPacket.vbs. The two scripts start similarly, except for the code that callout A in Listing 3 shows. In this code, the WScript::CreateObject method has a new parameter: "objWOL_", the name of an event handler. An event handler is a subroutine that specifies the action to perform when a specified event occurs. In this case, the script looks for the WOLError and WOLComplete events. The objWOL_WOLError and objWOL_WOLComplete subroutines specify the actions to perform when the WOLError or WOLComplete event occurs, respectively. These subroutines appear at the end of the script.
If an error occurs during the script's execution, the event handler directs the script to the objWOL_WOLError subprocedure. The objWOL_WOL-Error subprocedure displays a message box that details the error. The script then quits.
When no error occurs during the script's execution, the event handler directs the script to the objWOL_WOLComplete subprocedure. The objWOL_WOLComplete subprocedure displays a message box that states the packet was sent. The message box also details the subnet broadcast address, NIC MAC address, and NIC IP address (if applicable) for the PC to which the packet was sent.
Note that the WOLComplete event confirms only the success of sending the packet. This event doesn't confirm that the target PC has responded to the packet. Also note that if you don't have multiple NICs in the target PC, you can remove or comment out the code that callout B in Listing 3 shows.
After you execute SendMagicPacket.vbs or SendMagicPacketWithEvents.vbs, the target PC needs time to resume from its state of suspension, so you need to wait about a minute before you try to connect to the target machine. I recommend that you first try the script on a PC in a test lab to see how the script works and to gauge the length of time it takes the PC to wake up.
Give the Scripts a Try
If you use NICs and have PCs that support Wake on LAN, have a go at using SendMagicPacket.vbs or SendMagicPacketWithEvents.vbs to wake up your sleeping PCs. In an upcoming article, I'll show you how to use SendMagicPacket.vbs and a few other scripts to schedule tasks. Task scheduling can make your life much simpler.