Bryan Baker, a Product Engineer on the ArcGIS Server development team, contributed this post:
Working with ArcGIS Server requires you to stop and start services on occasion. In fact, the server object manager (SOM)itself is represented by the Windows service ArcGIS Server Object Manager, which you may sometimes want to stop or restart. On Windows, it can be painful to open Control Panel, open Administrative Tools, then the Services panel, and finally use the tools there to stop and start the service. You can make this a lot easier on Windows by creating scripts and shortcuts accessible from the desktop, or even better, from a toolbar on your Taskbar. Once created, you click on the toolbar menu in the Taskbar, and then on your script or shortcut, like this:
These examples make it simple to restart, start, and stop ArcGIS Server. These kinds of scripts can perform many operations on your server. Let’s see how to create these toolbar scripts and shortcuts.
Create a toolbar folder
First, use Windows Explorer to create a new folder to hold the shortcuts and scripts. The folder can be anywhere on your system. I’ll create my folder at C:ToolbarsScripts.
Create the script or shortcut
Inside the new Scripts folder, add the script or shortcut you want to appear. A script can use any of several available environments in Windows, including batch files, Windows Script Host, and the new Windows PowerShell. Let’s take the example of the Restart ArcGIS Server item shown above. This is actually a simple batch file. Here’s an easy way to create the batch file:
- Open Windows Explorer and navigate to the Scripts folder you created.
- In the right side of Windows Explorer, right-click an empty area and choose New – Text Document.
- Rename the document: Restart ArcGIS Server.bat. Windows warns you about changing the extension–go ahead and confirm.
- To open the batch file for editing, right-click on it and select Edit. It’ll open in Notepad.
Note: You can also add a shortcut to a program, either by copying an existing shortcut or creating a new one (right-click and choose New-Shortcut). For example, you can add a shortcut to ArcCatalog by navigating to it in the Start menu, then right-click and drag the ArcCatalog shortcut into the Windows Explorer folder for Scripts, and in the pop-up menu choose Copy Here.
Enter the script commands
With the script batch file open in Notepad or other text editor, add the commands you want to run. Batch files have a number of commands you can use, and can run anything you can do at a command line. To start and stop services, you can use the Windows “net start” and “net stop” commands. These commands start or stop the service you name in the command. You can get the name of the service from the Services dialog in Control Panel (some services have shorter names, for example, the World Wide Web Publishing Service is also W3SVC).
For the Restart ArcGIS Server batch file, we can enter these commands in the batch file, one per line:
net stop "ArcGIS Server Object Manager" net start "ArcGIS Server Object Manager"
Save the file and close Notepad.
Note: You might need to add commands for other services that are related to the service. For example, if you use SQL Server in your ArcGIS Server, you can add a command to start or stop that service if necessary.
Add the folder as a new toolbar
Finally, add the toolbar to the Taskbar. To do this:
- Right-click on any open spot on the Taskbar.
- In the context menu, choose Toolbars – New Toolbar…
- In the New Toolbar dialog that opens, navigate to the Scripts folder you created earlier.
- Click OK.
The folder should appear in the Taskbar as in the image below. You can then click the >> on the toolbar to run the scripts or shortcuts in it.
Optional: Set icons for scripts
The example above showed icons for the scripts, rather than the default batch file icon. If you want to change the icon, you need to create a shortcut to the batch file and use the shortcut instead. Here’s one approach:
- In Windows Explorer, create a new folder to hold the actual batch files. Within the Scripts folder, create a subfolder called Batch.
- Move the batch file(s) to the new Batch folder.
- Right-click on the batch file and drag it into the Scripts folder. Upon releasing the mouse, choose to Create Shortcuts Here.
- In the Scripts folder, right-click on the new shortcut and choose Properties.
- In the Properties dialog, on the Shortcut tab, click Change Icon… (dismiss the warning that no icons are in the batch file).
- Navigate to the icon or the program (.exe or .dll) that contains an icon to use. In the example above, I used the ArcCatalog icon, available at <ArcGIS install>binArcCatalog.exe.
- Optionally, change the name of the shortcut in the General tab.
- Click OK in the two dialogs to confirm the icon selection.
If you create lots of scripts and shortcuts, you can create folders within your toolbar folder, and add scripts or shortcuts within these subfolders. The subfolders will then be available to mouse-over and expand when you click on the toolbar.
These scripts and shortcuts can be very handy for many operations. Other examples include
- Restarting other services, such as the IIS Web server or ArcIMS
- Shortcuts to programs, such as ArcCatalog or ArcMap
- Shortcuts to files or folders, such as a log folder or a configuration file
- Connecting network drives (“net use” command)
- Backup commands
As a more complex example, I have a script that starts several services after a delay of 5 minutes (using the Sleep command in the Windows Server 2003 Resource Kit Tools); I have that script set to run on machine startup, so that I can start working on other tasks without the overhead of a lot of service startups, which is useful on a development computer. I’m sure you can think of many more creative uses of toolbars, scripts and shortcuts!
A zip file with the scripts and shortcuts discussed above is available here. It includes some additional sample scripts for ArcIMS and IIS, plus shortcuts to some commonly used Windows utilities.