コンピュータのデバイス以外のドライバ サービス、およびドライバ以外のサービスを取得します。
オーバーロードの一覧
デバイス ドライバ サービス以外の、ローカル コンピュータのすべてのサービスを取得します。
[Visual Basic] Overloads Public Shared Function GetServices() As ServiceController()
[JScript] public static function GetServices() : ServiceController[];
デバイス ドライバ サービス以外の、指定したコンピュータのすべてのサービスを取得します。
[Visual Basic] Overloads Public Shared Function GetServices(String) As ServiceController()
[C++] public: static ServiceController* GetServices(String*) [];
[JScript] public static function GetServices(String) : ServiceController[];
使用例
[Visual Basic, C#, C++] ServiceController クラスを使用して、ローカル コンピュータで実行しているサービスを表示する例を次に示します。
[Visual Basic, C#, C++] メモ ここでは、GetServices のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
Dim scServices() As ServiceController
scServices = ServiceController.GetServices()
' Display the list of services currently running on this computer.
Console.WriteLine("Services running on the local computer:")
Dim scTemp As ServiceController
For Each scTemp In scServices
If scTemp.Status = ServiceControllerStatus.Running Then
' Write the service name and the display name
' for each running service.
Console.WriteLine()
Console.WriteLine(" Service : {0}", scTemp.ServiceName)
Console.WriteLine(" Display name: {0}", scTemp.DisplayName)
' Query WMI for additional information about this service.
' Display the start name (LocalSytem, etc) and the service
' description.
Dim wmiService As ManagementObject
wmiService = New ManagementObject("Win32_Service.Name='" + scTemp.ServiceName + "'")
wmiService.Get()
Console.WriteLine(" Start name: {0}", wmiService("StartName"))
Console.WriteLine(" Description: {0}", wmiService("Description"))
End If
Next scTemp
[C#]
ServiceController[] scServices;
scServices = ServiceController.GetServices();
// Display the list of services currently running on this computer.
Console.WriteLine("Services running on the local computer:");
foreach (ServiceController scTemp in scServices)
{
if (scTemp.Status == ServiceControllerStatus.Running)
{
// Write the service name and the display name
// for each running service.
Console.WriteLine();
Console.WriteLine(" Service : {0}", scTemp.ServiceName);
Console.WriteLine(" Display name: {0}", scTemp.DisplayName);
// Query WMI for additional information about this service.
// Display the start name (LocalSytem, etc) and the service
// description.
ManagementObject wmiService;
wmiService = new ManagementObject("Win32_Service.Name='" + scTemp.ServiceName + "'");
wmiService.Get();
Console.WriteLine(" Start name: {0}", wmiService["StartName"]);
Console.WriteLine(" Description: {0}", wmiService["Description"]);
}
}
[C++]
ServiceController * scServices[] = ServiceController::GetServices();
// Display the list of services currently running on this computer.
Console::WriteLine("Services running on the local computer:");
for (int i=0; i<scServices->Length; i++)
{
ServiceController *scTemp = scServices[i];
if (scTemp)
{
if (scTemp->Status == ServiceControllerStatus::Running)
{
// Write the service name and the display name
// for each running service.
Console::WriteLine();
Console::WriteLine(" Service : {0}", scTemp->ServiceName);
Console::WriteLine(" Display name: {0}", scTemp->DisplayName);
// Query WMI for additional information about this service.
// Display the start name (LocalSytem, etc) and the service
// description.
ManagementObject *wmiService;
String *objPath;
objPath = String::Format(S"Win32_Service.Name='{0}'", scTemp->ServiceName);
wmiService = new ManagementObject(objPath);
if (wmiService)
{
wmiService->Get();
Object *objStartName = wmiService->get_Item(S"StartName");
Object *objDescription = wmiService->get_Item(S"Description");
if (objStartName)
{
Console::WriteLine(" Start name: {0}", objStartName->ToString());
}
if (objDescription)
{
Console::WriteLine(" Description: {0}", objDescription->ToString());
}
}
}
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
参照
ServiceController クラス | ServiceController メンバ | System.ServiceProcess 名前空間