Recipe 7.7. Viewing the List of ServicesProblemYou want to view all the services that are installed on a server. SolutionUsing a graphical user interface
Using a command-line interface:This command lists detailed output for all the running services: > sc \\<ServerName> query And this command lists all services: > psservice \\<ServerName> query If you want only a list of names of all running services, as opposed to detailed output, use this: > sc \\<ServerName> query | findstr SERVICE_NAME Or you can use any of these commands to list the installed services: > srvinfo -nf \\<ServerName> > psservice \\<ServerName> query | findstr SERVICE_NAME > wmic /node:"<ServerName>" service list Using VBScript' This code prints the list of services on a machine ' ------ SCRIPT CONFIGURATION ------ strComputer = "<ServerName>" ' e.g., fs-rtp01 (use . for local server) boolShowDetails = TRUE ' set to FALSE to display list w/o details ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set objServices = objWMI.InstancesOf("Win32_Service") for each objService in objServices WScript.Echo objService.Name if boolShowDetails = TRUE then for each objProp in objService.Properties_ ' Print out NULL if the property is blank if IsNull(objProp.Value) then Wscript.Echo " " & objProp.Name & " : NULL" else ' If the value is an array, we need to iterate through each element ' of the array if objProp.IsArray = TRUE then For I = LBound(objProp.Value) to UBound(objProp.Value) wscript.echo " " & objProp.Name & " : " & objProp.Value(I) next else ' If the property was not NULL or an array, we print it wscript.echo " " & objProp.Name & " : " & objProp.Value end if end if next WScript.Echo "" end if next DiscussionUsing a graphical user interfaceYou can target a remote server by right-clicking the Services icon in the left pane and selecting Connect to another computer. Enter the name of the target computer and click OK. Using VBScriptThe scripting solution prints each service by using the InstancesOf method on the Win32_Service class. As it loops through each service, it prints all of the properties by looping over the Properties_ method. It then does a couple of checks to determine the type of value it needs to print. See AlsoRecipe 7.1 |