July 2000

The Service.vbs Script


RSS
Subscribe to Windows IT Pro | See More Resource Kit Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Gives you powerful command-line control of remote services

Centralizing and automating any Windows NT shop requires some way to reach across a network to determine which services are running on a given server, examine how those services are configured (e.g., do they start up automatically or manually, do they have a service account associated with them), and change the configuration remotely. You can buy products to help with these tasks (for a review of one such product, see Oswald Forster, "ServiceKeeper 1.4.10," page 130). However, NT's Server Manager can also do many of these jobs. Server Manager replicates the Control Panel Services dialog box and can display that dialog box for any machine in its list of servers. But you can't control Server Manager from the command line, so it can't help you if you need to use a batch file to turn services on or off. Of course, you can use the Net Start and Net Stop commands to turn a service on and off, but only on the local computer.

The Microsoft Windows NT Server 4.0 Resource Kit Supplement 4 includes a script named service.vbs that lets you start or stop a service remotely. To shut down the DHCP server service on a remote machine named \charlie and restart the service, you could execute the commands

cscript service.vbs /x /n dhcpserver /s charlie
cscript service.vbs /g /n dhcpserver /s charlie

These examples assume that \charlie recognizes you as an administrator. If not, your command can include the name and password of an administrator account. You use the /u option to specify the user account and the /w option to specify the password. If \charlie recognizes an administrative account named adminguy with password swordfish, you can start the DHCP server on \charlie with the command

cscript service.vbs /g /n dhcpserver /s charlie /u adminguy /w swordfish

Many other service.vbs options exist. The following command contains a short list (you can use the cscript service.vbs /? command to get the complete list):

cscript service.vbs <actionoption> /n <servicename> /s <servername> /u <adminaccount> /w <password>

Actionoption can be /g to start a service, /x to stop a service, /r to remove a service from the computer, or /d to list a service's dependencies. To find out a service's name, you can use the /l (i.e., list) option. For example, if I type

cscript service.vbs /l /s 
 charlie

I'll see a list of all the services on \charlie (whether they're running or not), their display name (e.g., Microsoft DHCP Server), and their actual name (e.g., dhcpserver). Again, you might need to use the /u and /w options to specify a username and password for an administrator account.

Nifty as service.vbs is, it can't do every service-related task. I don't see a way to use service.vbs to change the name of the service account for services that don't use the standard "system" account. However, you can use the script to remotely install a service. First, you copy the file (or files) that makes up a service to the remote machine. For example, you can use the Net Use command to access an administrative share and copy the file to \winnt\system32. Then, you just type

cscript service.vbs /i /e <filename> /n <servicename> /c <displayname>

For filename, substitute the full pathname to the service's program file. Replace servicename with the service's short internal name (e.g., dhcpserver), and replace displayname with the display name (e.g., Microsoft DHCP Server). The command to install a new service that controls that wireless automatic lawnmower of yours might look like

cscript service.vbs /i /e c:\winnt\system32\buzz.exe /n mowrservice /c "Ronco Automatic Lawnmower Service"

Remember that perhaps the best thing about service.vbs is that, because it's a script, you have the source code. So, you can use it as a springboard to craft an even better utility.

End of Article



Windows IT Pro Community
Blogs





Top Viewed ArticlesView all articles
WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Windows 7 Sets Sales Record

Microsoft CEO Steve Ballmer described Windows 7's first ten days of sales as "fantastic" while in Japan yesterday. ...

Microsoft Completes Layoffs

Microsoft on Wednesday announced that it was laying off 800 more workers, bringing its previously-announced layoff plan to a close. ...


Related Events WinConnections and Microsoft® Exchange Connections

Deep Dive into Windows Server 2008 R2 presented by John Savill

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


SQL Server Magazine Office & SharePoint Pro DevProConnections asp.netPRO ITTV
IT Library Technology Resource Directory Connected Home Windows SuperSite
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc.     Terms of Use | Privacy Statement