Original article here.
You can make the server execute a script at shutdown time by using the Group Policy Editor, which is an MMC (Microsoft Management Console) snap-in. I will explain how to use the Group Policy Editor shortly, but first, we need to create the batch file that will shut down the Exchange services.
The batch file is very short, and you can create it in Notepad (figure 1):
Figure 1: The Batch File in Notepad
Here is the text that I have used, in case you want to copy/paste it, rather than type it yourself:
net stop MSExchangeES /y
net stop MSExchangeIS /y
net stop MSExchangeMTA /y
net stop MSExchangeSA /y
net stop WinHttpAutoProxySvc /y
Or, you can download the completed file from here http://www.leederbyshire.com/DL/ExchShutdown.zip
For this example, I am going to save the file in the root of my server’s C: drive, but remember that you can also save it in a shared folder, in case you want it to be accessed by several servers.
Now, we are going to use the Group Policy Editor to configure the server to execute this batch file every time it is shut down. Click on Run on your server’s Start Menu, and type gpedit.msc , then click OK (figure 2) to start the Group Policy Editor.
Figure 2: Starting the Group Policy Editor
Once the Group Policy Editor has started, expand the tree in the left-hand window through Computer Configuration, Windows Settings, and then select Scripts (Startup/Shutdown), so that you can see the Startup and Shutdown objects in the right-hand pane. Right-click Shutdown and select the Properties open from the context menu as shown in figure 3.
Figure 3: The Group Policy Editor main window
You probably do not have any shutdown scripts configured yet, so the list will probably be empty (figure 4):
Figure 4: The list of Shutdown Scripts for the Local Computer
Click the Add button, and then click on Browse… to navigate to the location of the batch file that you created. Remember that I saved the file on my C: drive, but your location may be different. Once you have located the file in the browser dialog, select it, and click Open to indicate the file location. Of course, you could also just type the full path into the Script Name field.
Figure 5: Adding a Shutdown Script to the list
Once you have the script name field populated with the batch file path, click OK to add it to the list of Shutdown Scripts, as shown in figure 6:
Figure 6: The Shutdown Script added to the list
Click OK to save the changes, close the Group Policy Editor, and the procedure is finished.
This probably isn’t something you can test immediately (unless you’re working very late), but the next time you need to shutdown or reboot the server, you should find that it shuts down a lot quicker. In my case, it now takes about three minutes instead of twenty minutes. Of course, it would all be a lot simpler if the Exchange setup program somehow automatically arranged for the Exchange Services to shutdown first wouldn’t it? Perhaps that isn’t as simple as it sounds.
(This article is based on a similar one, which I wrote some time earlier. Thanks to the feedback I received, most notably from Andras Gaal, I am able to describe this improved method, which offers automation of the script, rather than manual execution).
Bad Behavior has blocked 49 access attempts in the last 7 days.