Processes and Services in VS .NET

Creation Code39 in VS .NET Processes and Services
14 Processes and Services
Code39 Encoder In .NET
Using Barcode maker for .NET Control to generate, create Code 39 Extended image in Visual Studio .NET applications.
Dependent Services
Scan USS Code 39 In .NET
Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
If you want to display the dependent services of a service, you have to access the attribute DependentServices of the NET object SystemServiceProcessServiceController:
Drawing Barcode In VS .NET
Using Barcode drawer for VS .NET Control to generate, create barcode image in .NET framework applications.
get-service iisadmin | % { $_DependentServices }
Decoding Bar Code In .NET Framework
Using Barcode scanner for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
Figure 145 Documentation for the NET class SystemServiceProcess
Code39 Encoder In C#
Using Barcode creation for VS .NET Control to generate, create Code 39 Full ASCII image in VS .NET applications.
ServiceController in the NET Framework class library documentation [MSDN01]
Code 39 Extended Generator In .NET
Using Barcode printer for ASP.NET Control to generate, create Code39 image in ASP.NET applications.
Windows Services
Print Code-39 In VB.NET
Using Barcode maker for VS .NET Control to generate, create Code 39 Extended image in Visual Studio .NET applications.
14 PROCESSES AND SERVICES
Making UPC Symbol In Visual Studio .NET
Using Barcode generator for Visual Studio .NET Control to generate, create UPCA image in .NET framework applications.
Figure 146 Documentation for the WMI class Win32_Service in the WMI
Printing Code 128 Code Set A In VS .NET
Using Barcode drawer for VS .NET Control to generate, create Code-128 image in .NET framework applications.
schema class reference [MSDN05]
Bar Code Drawer In VS .NET
Using Barcode creation for .NET framework Control to generate, create barcode image in Visual Studio .NET applications.
The result for Windows Server 2003 Release 2 is shown in Figure 147
Generating Code 3/9 In VS .NET
Using Barcode creation for .NET Control to generate, create Code 3 of 9 image in VS .NET applications.
Figure 147 The dependent services of IISAdmin
Royal Mail Barcode Printer In .NET Framework
Using Barcode printer for .NET framework Control to generate, create Royal Mail Barcode image in Visual Studio .NET applications.
14 Processes and Services
Encoding Code-39 In VB.NET
Using Barcode generator for Visual Studio .NET Control to generate, create Code-39 image in Visual Studio .NET applications.
The dependent services of a system service can alternatively be displayed in WMI, via the method GetRelated() in the class ManagementObject in the NET class library The following command displays the services that depend on the service IISAdmin:
Bar Code Drawer In Java
Using Barcode printer for Java Control to generate, create barcode image in Java applications.
(get-wmiObject win32_service - lter "Name = 'iisadmin'")PSBaseGetRelated("Win32_Service") | select name
UCC - 12 Generator In Java
Using Barcode drawer for Java Control to generate, create UPC-A image in Java applications.
The same object volume can be displayed via a WQL query with relation to the xed expression AssocClass (see Figure 148):
Code39 Creation In C#
Using Barcode drawer for .NET Control to generate, create Code 39 image in VS .NET applications.
([wmiSearcher]"Associators of {Win32_ServiceName='iisadmin'} Where AssocClass=Win32_DependentService Role=Antecedent")get()
Encoding Bar Code In Java
Using Barcode drawer for Java Control to generate, create bar code image in Java applications.
Figure 148 Displaying the dependent services
Paint Data Matrix 2d Barcode In VB.NET
Using Barcode encoder for .NET framework Control to generate, create Data Matrix ECC200 image in .NET framework applications.
Starting and Stopping Services
GS1 128 Printer In .NET Framework
Using Barcode creator for ASP.NET Control to generate, create GS1-128 image in ASP.NET applications.
If you want to change the service status, you can use the following commandlets:
Scanning EAN / UCC - 13 In VS .NET
Using Barcode recognizer for .NET Control to read, scan read, scan image in .NET framework applications.
Suspend-Service Resume-Service Stop-Service Start-Service Restart-Service
Windows Services
Here, the service names have to be indicated as parameters The following command also starts the service IISAdmin:
Start-Service IISADMIN
If you want to stop system services with dependent services, you have to add the parameter force (see Figure 149):
Stop-Service IISADMIN force
14 PROCESSES AND SERVICES
Figure 149 Stop-Service without force will not work if the service has dependent services Because the commandlet Start-Service is valid only for the local computer, you have to get back to the WMI class Win32_Service to start a service on a remote system The following command starts a system service on another computer:
Get-WmiObject -computer E02 Win32_Service -Filter "Name='Alerter'" | Start-Service
TIP The commandlet Restart-Service executes the reboot of a service (end rst, then start) If the service hasn t been started before, it will get started now
14 Processes and Services
Changing Service Attributes
You can in uence the attributes of services, such as its booting, with SetService:
Set-Service IISADMIN -startuptype "manual"
Installation of New Windows Services
Executables that implement Windows services can be registered on your system by using the commandlet New-Service, as follows:
New-Service -Name "WWWAppServer" -binaryPathName j:\software\wcf_serverexe -Description "Application Server for World Wide -DisplayName "World Wide Wings Application Server"
The execution of this command will create a new entry in the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
After that, the service will be visible in the Service Manager in the Control Panel Then, you can start the service using Start-Service:
Start-Service WWWAppServer
Change Service Con guration
As with many other WMI classes, the properties of a Win32_Service objects are read-only To change the con guration, you need to call the Change() method Figure 1410 shows the available parameters, and Figure 1411 shows an example You don t need to pass values for all parameters; if you want a property to stay unchanged, just pass $null (see Listing 143) Listing 143 Change Service Con guration
"Before:" Get-WmiObject Win32_Service - lter "name='WWWAppServer'" | select startname, startmode
Windows Services
$service = Get-WmiObject Win32_Service - lter "name='WWWAppServer'" $servicechange($null,$null,$null,$null,"Manual",$null,"itv\hs", "secret+123") "After:" Get-WmiObject Win32_Service - lter "name='WWWAppServer'" | select startname, startmode
14 PROCESSES AND SERVICES
Figure 1410 Description of the Change() method in the Win32_Service
class
Figure 1411 Changing a Windows service from Localsystem and Auto to a
speci c account and manual start
14 Processes and Services
Summary
The administration of processes and services is one of the core tasks of Windows administration WPS provides easy-to-use commandlets for both tasks, including the following:
Get-Process Stop-Process Start-Process (from PowerShell Community Extensions, PSCX) Set-Service Suspend-Service Resume-Service Stop-Service Start-Service Restart-Service Set-Service
C H A P T E R
COMPUTERS AND HARDWARE
In this chapter:
Computer Settings Hardware Event Logs Performance Counters 281 284 290 292
This chapter covers computer settings (for example, operating system versions, BIOS settings, boot con guration, environment variables), installed hardware, the management of print jobs, Windows event logs, and performance counters Examples in the chapter include:
Read computer settings Enumerate hardware devices and their properties Enumerate the available event logs Read event log entries Read data from performance counters Enumerate printers Administration of print jobs (pause, resume, cancel)
Computer Settings
There is no special commandlet for the displaying of information about the computer You can get important information about the computer and the installed software with the WMI classes Win32_Computersystem and Win32_OperatingSystem:
15 Computers and Hardware
Get-WmiObject Win32_Computersystem Get-WmiObject Win32_OperatingSystem
The serial number of the computer is displayed with the following:
Get-WmiObject Win32_OperatingSystem | select serialnumber
You can get the version number of the software with the property Version in the WMI class Win32_OperatingSystem or with the NET class SystemEnvironment: