ServiceController.DisplayName 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置服务的友好名称。
public:
property System::String ^ DisplayName { System::String ^ get(); void set(System::String ^ value); };
public:
property System::String ^ DisplayName { System::String ^ get(); };
public string DisplayName { get; set; }
public string DisplayName { get; }
[System.ServiceProcess.ServiceProcessDescription("SPDisplayName")]
public string DisplayName { get; set; }
member this.DisplayName : string with get, set
member this.DisplayName : string
[<System.ServiceProcess.ServiceProcessDescription("SPDisplayName")>]
member this.DisplayName : string with get, set
Public Property DisplayName As String
Public ReadOnly Property DisplayName As String
属性值
服务的友好名称,可用于标识该服务。
- 属性
例外
DisplayName 为 null
。
访问 API 时出错。
未找到服务。
示例
以下示例使用 ServiceController 类显示依赖于事件日志服务的服务集。
ServiceController^ sc = gcnew ServiceController( "Event Log" );
array<ServiceController^>^scServices = nullptr;
if ( sc )
{
scServices = sc->DependentServices;
}
if ( sc && scServices )
{
// Display the list of services dependent on the Event Log service.
if ( scServices->Length == 0 )
{
Console::WriteLine( "There are no services dependent on {0}", sc->ServiceName );
}
else
{
Console::WriteLine( "Services dependent on {0}:", sc->ServiceName );
for each (ServiceController^ scTemp in scServices)
{
Console::WriteLine(" {0}", scTemp->DisplayName);
}
}
}
ServiceController sc = new ServiceController("Event Log");
ServiceController[] scServices = sc.DependentServices;
// Display the list of services dependent on the Event Log service.
if (scServices.Length == 0)
{
Console.WriteLine("There are no services dependent on {0}",
sc.ServiceName);
}
else
{
Console.WriteLine("Services dependent on {0}:",
sc.ServiceName);
foreach (ServiceController scTemp in scServices)
{
Console.WriteLine(" {0}", scTemp.DisplayName);
}
}
Dim sc As New ServiceController("Event Log")
Dim scServices As ServiceController() = sc.DependentServices
' Display the list of services dependent on the Event Log service.
If scServices.Length = 0 Then
Console.WriteLine("There are no services dependent on {0}", sc.ServiceName)
Else
Console.WriteLine("Services dependent on {0}:", sc.ServiceName)
Dim scTemp As ServiceController
For Each scTemp In scServices
Console.WriteLine(" {0}", scTemp.DisplayName)
Next scTemp
End If
注解
可以将 设置为 DisplayName 空字符串 (“”) ,但将 属性设置为 null
会引发异常。