Sunday 15 March 2015

Batch File for Remote shutdown and Wake on Demand using Wake on LAN

For long weekends  or public holiday's its good that all the desktops were shutdown. The below method uses Windows Remote shutdown feature and Wake-On-Lan features to remotely shutdown the desktops and power it on whenever required.


Settings to do on Target PC


1. Turn on the target PC.
2. Open run->secpol.mnc
3.In Security settings, Expand "Local Polices->User rights assignment"
4.Double click on "Force shutdown from a remote system properties".
5.Click on Add user (test) and group
6.click on object types, select "built in security principles and users" and click OK
7.Goto advanced -> find now ->select administrator, everyone, required user (eg:test) and click OK.
8. Click Apply and then OK.
9. Close the window.

Open Port 445: Open TCP port 445 on target computer

1.Goto start->settings->control panel->security centre.
2. Open windows firewall -> Exceptions Tab.
3.Select the following line "File Sharing and printers" and press ok.
4. If this line is missing click on Add port ->choose TCP port 445.
5. Then got to start->settings-control panel->system.
6. Select the remote tab; check the "Allow users to connect remotely to this computer".

Settings to do on Control PC


1.Turn on main PC.
2. Open cmd
3. Use command "net use \\Target PC IP password /user: username 'enter'

Example: net use \\10.10.1.10 test /user: test

Note: IP address used in net use command should be reachable from the main PC.  If that is not reachable then the following error will be shown as net use command output.

 "System error 53 has occurred. The network path was not found".

4. Check the message "The command completed successfully" is shown.
5. Similarly add Target PC IPs.
6. Command "net use" will show you the table containing the Target PC entries.
7. Type "shutdown -i", there opens a remote shutdown dialog box.
8.  Click Add and enter the target ip address. Repeat the same for all IPs.
9. Select the operation "shutdown/restart".
10. Configure the display warning for specific time (sec) before shutdown\restart.
11. Give comments on the Task and click ok.

Wake On LAN

 WakeOnLan, as the name already suggests, is a tool that can boot or wake a computer (on the same local network) by sending a magic packet to the network adapter of the target computer.

 

Prerequisites

1.      All network cards and BIOS are compatible or support the use of Magic Packet.

2.      All PCs should be reachable from main PC, ie from where we are sending magic packet.

3.      All PCs MAC addresses and IP Addresses.

4.      Tool to send magic packet should be installed in main PC.You can download wolcmd from http://www.depicus.com/wake-on-lan/wake-on-lan-cmd.aspx


 To check if your network card is compatible with magic packets:

  • Right click on My Computer and click Manage.
  • Go to Device Manager/Network Cards.
  • Right click on your Network Card then Properties.
  • Search for the following the words: "Magic Packet", "Wake On Magic Packet", "Wake On Lan" or "Wake" - verify that all options related to these words are being activated
  • If you found nothing, you may be required to update the drivers of your Network card

 BIOS

To check if your BIOS is compatible, follow these steps:

  • Enter the BIOS when you start the computer by pressing ESC, F2, F5, F12 or DEL, depending on your system,
  • Once in the BIOS, go to POWER Options and enable Wake-On-LAN, or any similar option.

 Wake on LAN GUI tool: 

·         Launch the Wake on LAN GUI tool.

·         Provide the MAC address, IP Address, Subnet Mask and port of the target PC.

·         Click on Wake me UP.

 Wake on LAN Command line Tool: 

·         Open command prompt and Go to the directory where this command line tool is present.

·         Issue the following command.

            wolcmd [mac address] [ipaddress] [subnet mask] [port number]

 

 

Batch file wakenow.bat

wolcmd.exe 0007E90E7A66 10.10.10.10  255.0.0.0 9

wolcmd.exe 50E549467AAD 10.10.10.11 255.0.0.0 9

 

Batch file Sleepnow.bat

net use \\10.10.10.10 test /user:test  

shutdown -m \\10.10.10.10 -s -t 1 -c "Going to shutdown.... "

net use \\10.10.10.11 test /user:test

shutdown -m \\10.10.10.11 -s -t 1 -c "Going to shutdown..