PerformanceCounterCategory.InstanceExists Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Kategorinin belirtilen performans nesnesi örneğini içerip içermediğini belirler.
Aşırı Yüklemeler
InstanceExists(String) |
Belirtilen performans nesnesi örneğinin bu PerformanceCounterCategoryCategoryName nesnenin özelliği tarafından tanımlanan kategoride var olup olmadığını belirler. |
InstanceExists(String, String) |
Yerel bilgisayardaki belirtilen bir kategorinin belirtilen performans nesnesi örneğini içerip içermediğini belirler. |
InstanceExists(String, String, String) |
Belirtilen bilgisayardaki belirtilen bir kategorinin belirtilen performans nesnesi örneğini içerip içermediğini belirler. |
InstanceExists(String)
Belirtilen performans nesnesi örneğinin bu PerformanceCounterCategoryCategoryName nesnenin özelliği tarafından tanımlanan kategoride var olup olmadığını belirler.
public:
bool InstanceExists(System::String ^ instanceName);
public bool InstanceExists (string instanceName);
member this.InstanceExists : string -> bool
Public Function InstanceExists (instanceName As String) As Boolean
Parametreler
- instanceName
- String
Bu performans sayacı kategorisinde aranacak performans nesnesi örneği.
Döndürülenler
true
kategori belirtilen performans nesnesi örneğini içeriyorsa; aksi takdirde , false
.
Özel durumlar
CategoryName özelliğidirnull
. Özelliği ayarlanmamış olabilir.
instanceName
parametresidirnull
.
Temel alınan sistem API'sine yapılan çağrı başarısız oldu.
Yönetici ayrıcalıkları olmadan yürütülen kod bir performans sayacını okumaya çalıştı.
Örnekler
Aşağıdaki kod örneği, içinde bir PerformanceCounter örneğin bulunup bulunmadığına PerformanceCounterCategorykarar verir. İlk olarak, bir bilgisayar adının belirtilip belirtilmediğinden yola çıkarak uygun oluşturucuyu kullanarak bir nesne oluşturur PerformanceCounterCategory . Daha sonra, belirtilen örneğin var olup olmadığını belirlemek için kullanır InstanceExists(String) , ardından kullanıcıya bildirir. Örnek adı belirtilmezse, örnek varsayılan tek örnek adını kullanır.
public static void Main(string[] args)
{
string categoryName = "";
string instanceName = "";
string machineName = "";
bool objectExists = false;
PerformanceCounterCategory pcc;
const string SINGLE_INSTANCE_NAME = "systemdiagnosticsperfcounterlibsingleinstance";
// Copy the supplied arguments into the local variables.
try
{
categoryName = args[0];
instanceName = args[1];
machineName = (args[2]=="."? "": args[2]);
}
catch(Exception ex)
{
// Ignore the exception from non-supplied arguments.
}
// Use the given instance name or use the default single-instance name.
if (instanceName.Length==0)
{
instanceName = SINGLE_INSTANCE_NAME;
}
try
{
if (machineName.Length==0)
{
pcc = new PerformanceCounterCategory(categoryName);
}
else
{
pcc = new PerformanceCounterCategory(categoryName, machineName);
}
// Check whether the instance exists.
// Use the per-instance overload of InstanceExists.
objectExists = pcc.InstanceExists(instanceName);
}
catch(Exception ex)
{
Console.WriteLine("Unable to check for the existence of " +
"instance \"{0}\" in category \"{1}\" on " +
(machineName.Length>0? "computer \"{2}\":": "this computer:") +
"\n" + ex.Message, instanceName, categoryName, machineName);
return;
}
// Tell the user whether the instance exists.
Console.WriteLine("Instance \"{0}\" " + (objectExists? "exists": "does not exist") +
" in category \"{1}\" on " + (machineName.Length>0? "computer \"{2}\".": "this computer."),
instanceName, pcc.CategoryName, pcc.MachineName);
}
Sub Main(ByVal args() As String)
Dim categoryName As String = ""
Dim instanceName As String = ""
Dim machineName As String = ""
Dim objectExists As Boolean = False
Dim pcc As PerformanceCounterCategory
Const SINGLE_INSTANCE_NAME As String = _
"systemdiagnosticsperfcounterlibsingleinstance"
' Copy the supplied arguments into the local variables.
Try
categoryName = args(0)
instanceName = args(1)
machineName = IIf(args(2) = ".", "", args(2))
Catch ex As Exception
' Ignore the exception from non-supplied arguments.
End Try
' Use the given instance name or use the default single-instance name.
If instanceName.Length = 0 Then
instanceName = SINGLE_INSTANCE_NAME
End If
Try
If machineName.Length = 0 Then
pcc = New PerformanceCounterCategory(categoryName)
Else
pcc = New PerformanceCounterCategory(categoryName, machineName)
End If
' Check whether the instance exists.
' Use the per-instance overload of InstanceExists.
objectExists = pcc.InstanceExists(instanceName)
Catch ex As Exception
Console.WriteLine("Unable to check for the existence of " & _
"instance ""{0}"" in category ""{1}"" on " & _
IIf(machineName.Length > 0, _
"computer ""{2}"":", "this computer:") & vbCrLf & _
ex.Message, instanceName, categoryName, machineName)
Return
End Try
' Tell the user whether the instance exists.
Console.WriteLine("Instance ""{0}"" " & _
IIf(objectExists, "exists", "does not exist") & _
" in category ""{1}"" on " & _
IIf(machineName.Length > 0, _
"computer ""{2}"".", "this computer."), _
instanceName, pcc.CategoryName, pcc.MachineName)
End Sub
Açıklamalar
öğesinin InstanceExists bu aşırı yüklemesi değildir static
. Bir nesne oluşturmanızı PerformanceCounterCategory ve özelliğini ayarlamanızı CategoryName gerektirir.
Not
Windows Vista ve sonraki sürümlerde, Windows XP Professional x64 Edition veya Windows Server 2003'te etkileşimli olmayan bir oturumdan performans sayaçlarını okumak için, Performans İzleyicisi Kullanıcıları grubunun üyesi olmanız veya yönetici ayrıcalıklarına sahip olmanız gerekir.
Windows Vista ve sonraki sürümlerde performans sayaçlarına erişmek için ayrıcalıklarınızı yükseltmek zorunda kalmamak için kendinizi Performans İzleyicisi Kullanıcılar grubuna ekleyin.
Windows Vista ve sonraki sürümlerde, Kullanıcı Hesabı Denetimi (UAC) bir kullanıcının ayrıcalıkları belirler. Yerleşik Yöneticiler grubunun bir üyesi iseniz, size iki çalışma zamanı erişim belirteci atanır: Standart kullanıcı erişim belirteci ve yönetici erişim belirteci. Varsayılan olarak, standart kullanıcı rolünde olursunuz. Performans sayaçlarına erişen kodu yürütmek için öncelikle ayrıcalıklarınızı standart kullanıcıdan yöneticiye yükseltmeniz gerekir. Bir uygulamayı başlattığınızda, uygulama simgesine sağ tıklayıp yönetici olarak çalıştırmak istediğinizi belirterek bunu yapabilirsiniz.
Ayrıca bkz.
Şunlara uygulanır
InstanceExists(String, String)
Yerel bilgisayardaki belirtilen bir kategorinin belirtilen performans nesnesi örneğini içerip içermediğini belirler.
public:
static bool InstanceExists(System::String ^ instanceName, System::String ^ categoryName);
public static bool InstanceExists (string instanceName, string categoryName);
static member InstanceExists : string * string -> bool
Public Shared Function InstanceExists (instanceName As String, categoryName As String) As Boolean
Parametreler
- instanceName
- String
Aranacak performans nesnesi örneği.
- categoryName
- String
Aranacak performans sayacı kategorisi.
Döndürülenler
true
kategori belirtilen performans nesnesi örneğini içeriyorsa; aksi takdirde , false
.
Özel durumlar
categoryName
parametresi boş bir dizedir ("").
Temel alınan sistem API'sine yapılan çağrı başarısız oldu.
Yönetici ayrıcalıkları olmadan yürütülen kod bir performans sayacını okumaya çalıştı.
Örnekler
Aşağıdaki kod örneği, verilen PerformanceCounter örneğin içinde var olup olmadığını belirlemek için statik aşırı yüklemelerini InstanceExistsPerformanceCounterCategorykullanır. Aşırı yükleme, bir bilgisayar adının belirtilip belirtilmediğinden yola çıkarak seçilir. Örnek adı belirtilmezse, örnek varsayılan tek örnek adını kullanır.
public static void Main(string[] args)
{
string categoryName = "";
string instanceName = "";
string machineName = "";
bool objectExists = false;
const string SINGLE_INSTANCE_NAME = "systemdiagnosticsperfcounterlibsingleinstance";
// Copy the supplied arguments into the local variables.
try
{
categoryName = args[0];
instanceName = args[1];
machineName = args[2]=="."? "": args[2];
}
catch(Exception ex)
{
// Ignore the exception from non-supplied arguments.
}
// Use the given instance name or use the default single-instance name.
if (instanceName.Length==0)
{
instanceName = SINGLE_INSTANCE_NAME;
}
try
{
// Check whether the specified instance exists.
// Use the static forms of the InstanceExists method.
if (machineName.Length==0)
{
objectExists = PerformanceCounterCategory.InstanceExists(instanceName, categoryName);
}
else
{
objectExists = PerformanceCounterCategory.InstanceExists(instanceName, categoryName, machineName);
}
}
catch(Exception ex)
{
Console.WriteLine("Unable to check for the existence of " +
"instance \"{0}\" in category \"{1}\" on " +
(machineName.Length>0? "computer \"{2}\":": "this computer:") + "\n" +
ex.Message, instanceName, categoryName, machineName);
return;
}
// Tell the user whether the instance exists.
Console.WriteLine("Instance \"{0}\" " + (objectExists? "exists": "does not exist") +
" in category \"{1}\" on " + (machineName.Length>0? "computer \"{2}\".": "this computer."),
instanceName, categoryName, machineName);
}
Sub Main(ByVal args() As String)
Dim categoryName As String = ""
Dim instanceName As String = ""
Dim machineName As String = ""
Dim objectExists As Boolean = False
Const SINGLE_INSTANCE_NAME As String = _
"systemdiagnosticsperfcounterlibsingleinstance"
' Copy the supplied arguments into the local variables.
Try
categoryName = args(0)
instanceName = args(1)
machineName = IIf(args(2) = ".", "", args(2))
Catch ex As Exception
' Ignore the exception from non-supplied arguments.
End Try
' Use the given instance name or use the default single-instance name.
If instanceName.Length = 0 Then
instanceName = SINGLE_INSTANCE_NAME
End If
Try
' Check whether the specified instance exists.
' Use the static forms of the InstanceExists method.
If machineName.Length = 0 Then
objectExists = PerformanceCounterCategory.InstanceExists( _
instanceName, categoryName)
Else
objectExists = PerformanceCounterCategory.InstanceExists( _
instanceName, categoryName, machineName)
End If
Catch ex As Exception
Console.WriteLine("Unable to check for the existence of " & _
"instance ""{0}"" in category ""{1}"" on " & _
IIf(machineName.Length > 0, _
"computer ""{2}"":", "this computer:") & vbCrLf & _
ex.Message, instanceName, categoryName, machineName)
Return
End Try
' Tell the user whether the instance exists.
Console.WriteLine("Instance ""{0}"" " & _
IIf(objectExists, "exists", "does not exist") & _
" in category ""{1}"" on " & _
IIf(machineName.Length > 0, _
"computer ""{2}"".", "this computer."), _
instanceName, categoryName, machineName)
End Sub
Açıklamalar
Bakılacak belirli bir kategori belirtmeden bir performans nesnesi örneğinin bilgisayarda var olup olmadığını belirlemek mümkün değildir.
Not
Windows Vista ve sonraki sürümlerde, Windows XP Professional x64 Edition veya Windows Server 2003'te etkileşimli olmayan bir oturumdan performans sayaçlarını okumak için, Performans İzleyicisi Kullanıcıları grubunun üyesi olmanız veya yönetici ayrıcalıklarına sahip olmanız gerekir.
Windows Vista ve sonraki sürümlerde performans sayaçlarına erişmek için ayrıcalıklarınızı yükseltmek zorunda kalmamak için kendinizi Performans İzleyicisi Kullanıcılar grubuna ekleyin.
Windows Vista ve sonraki sürümlerde, Kullanıcı Hesabı Denetimi (UAC) bir kullanıcının ayrıcalıkları belirler. Yerleşik Yöneticiler grubunun bir üyesi iseniz, size iki çalışma zamanı erişim belirteci atanır: Standart kullanıcı erişim belirteci ve yönetici erişim belirteci. Varsayılan olarak, standart kullanıcı rolünde olursunuz. Performans sayaçlarına erişen kodu yürütmek için öncelikle ayrıcalıklarınızı standart kullanıcıdan yöneticiye yükseltmeniz gerekir. Bir uygulamayı başlattığınızda, uygulama simgesine sağ tıklayıp yönetici olarak çalıştırmak istediğinizi belirterek bunu yapabilirsiniz.
Ayrıca bkz.
Şunlara uygulanır
InstanceExists(String, String, String)
Belirtilen bilgisayardaki belirtilen bir kategorinin belirtilen performans nesnesi örneğini içerip içermediğini belirler.
public:
static bool InstanceExists(System::String ^ instanceName, System::String ^ categoryName, System::String ^ machineName);
public static bool InstanceExists (string instanceName, string categoryName, string machineName);
static member InstanceExists : string * string * string -> bool
Public Shared Function InstanceExists (instanceName As String, categoryName As String, machineName As String) As Boolean
Parametreler
- instanceName
- String
Aranacak performans nesnesi örneği.
- categoryName
- String
Aranacak performans sayacı kategorisi.
- machineName
- String
Kategori örneği çiftinin arandığı bilgisayarın adı.
Döndürülenler
true
kategori belirtilen performans nesnesi örneğini içeriyorsa; aksi takdirde , false
.
Özel durumlar
categoryName
parametresi boş bir dizedir ("").
-veya-
machineName
Parametre geçersiz.
Temel alınan sistem API'sine yapılan çağrı başarısız oldu.
Yönetici ayrıcalıkları olmadan yürütülen kod bir performans sayacını okumaya çalıştı.
Örnekler
Aşağıdaki kod örneği, verilen PerformanceCounter örneğin içinde var olup olmadığını belirlemek için statik aşırı yüklemelerini InstanceExistsPerformanceCounterCategorykullanır. Aşırı yükleme, bir bilgisayar adının belirtilip belirtilmediğinden yola çıkarak seçilir. Örnek adı belirtilmezse, örnek varsayılan tek örnek adını kullanır.
public static void Main(string[] args)
{
string categoryName = "";
string instanceName = "";
string machineName = "";
bool objectExists = false;
const string SINGLE_INSTANCE_NAME = "systemdiagnosticsperfcounterlibsingleinstance";
// Copy the supplied arguments into the local variables.
try
{
categoryName = args[0];
instanceName = args[1];
machineName = args[2]=="."? "": args[2];
}
catch(Exception ex)
{
// Ignore the exception from non-supplied arguments.
}
// Use the given instance name or use the default single-instance name.
if (instanceName.Length==0)
{
instanceName = SINGLE_INSTANCE_NAME;
}
try
{
// Check whether the specified instance exists.
// Use the static forms of the InstanceExists method.
if (machineName.Length==0)
{
objectExists = PerformanceCounterCategory.InstanceExists(instanceName, categoryName);
}
else
{
objectExists = PerformanceCounterCategory.InstanceExists(instanceName, categoryName, machineName);
}
}
catch(Exception ex)
{
Console.WriteLine("Unable to check for the existence of " +
"instance \"{0}\" in category \"{1}\" on " +
(machineName.Length>0? "computer \"{2}\":": "this computer:") + "\n" +
ex.Message, instanceName, categoryName, machineName);
return;
}
// Tell the user whether the instance exists.
Console.WriteLine("Instance \"{0}\" " + (objectExists? "exists": "does not exist") +
" in category \"{1}\" on " + (machineName.Length>0? "computer \"{2}\".": "this computer."),
instanceName, categoryName, machineName);
}
Sub Main(ByVal args() As String)
Dim categoryName As String = ""
Dim instanceName As String = ""
Dim machineName As String = ""
Dim objectExists As Boolean = False
Const SINGLE_INSTANCE_NAME As String = _
"systemdiagnosticsperfcounterlibsingleinstance"
' Copy the supplied arguments into the local variables.
Try
categoryName = args(0)
instanceName = args(1)
machineName = IIf(args(2) = ".", "", args(2))
Catch ex As Exception
' Ignore the exception from non-supplied arguments.
End Try
' Use the given instance name or use the default single-instance name.
If instanceName.Length = 0 Then
instanceName = SINGLE_INSTANCE_NAME
End If
Try
' Check whether the specified instance exists.
' Use the static forms of the InstanceExists method.
If machineName.Length = 0 Then
objectExists = PerformanceCounterCategory.InstanceExists( _
instanceName, categoryName)
Else
objectExists = PerformanceCounterCategory.InstanceExists( _
instanceName, categoryName, machineName)
End If
Catch ex As Exception
Console.WriteLine("Unable to check for the existence of " & _
"instance ""{0}"" in category ""{1}"" on " & _
IIf(machineName.Length > 0, _
"computer ""{2}"":", "this computer:") & vbCrLf & _
ex.Message, instanceName, categoryName, machineName)
Return
End Try
' Tell the user whether the instance exists.
Console.WriteLine("Instance ""{0}"" " & _
IIf(objectExists, "exists", "does not exist") & _
" in category ""{1}"" on " & _
IIf(machineName.Length > 0, _
"computer ""{2}"".", "this computer."), _
instanceName, categoryName, machineName)
End Sub
Açıklamalar
Bakılacak belirli bir kategori belirtmeden bir performans nesnesi örneğinin bilgisayarda var olup olmadığını belirlemek mümkün değildir.
Yerel bilgisayarı belirtmek için "." kullanabilirsiniz.
Not
Windows Vista ve sonraki sürümlerde, Windows XP Professional x64 Edition veya Windows Server 2003'te etkileşimli olmayan bir oturumdan performans sayaçlarını okumak için, Performans İzleyicisi Kullanıcıları grubunun üyesi olmanız veya yönetici ayrıcalıklarına sahip olmanız gerekir.
Windows Vista ve sonraki sürümlerde performans sayaçlarına erişmek için ayrıcalıklarınızı yükseltmek zorunda kalmamak için kendinizi Performans İzleyicisi Kullanıcılar grubuna ekleyin.
Windows Vista ve sonraki sürümlerde, Kullanıcı Hesabı Denetimi (UAC) bir kullanıcının ayrıcalıkları belirler. Yerleşik Yöneticiler grubunun bir üyesi iseniz, size iki çalışma zamanı erişim belirteci atanır: Standart kullanıcı erişim belirteci ve yönetici erişim belirteci. Varsayılan olarak, standart kullanıcı rolünde olursunuz. Performans sayaçlarına erişen kodu yürütmek için öncelikle ayrıcalıklarınızı standart kullanıcıdan yöneticiye yükseltmeniz gerekir. Bir uygulamayı başlattığınızda, uygulama simgesine sağ tıklayıp yönetici olarak çalıştırmak istediğinizi belirterek bunu yapabilirsiniz.
Ayrıca bkz.
Şunlara uygulanır
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin