ManagementClass.CreateInstance Método
Definição
Inicializa uma nova instância da classe WMI.Initializes a new instance of the WMI class.
public:
System::Management::ManagementObject ^ CreateInstance();
public System.Management.ManagementObject CreateInstance ();
member this.CreateInstance : unit -> System.Management.ManagementObject
Public Function CreateInstance () As ManagementObject
Retornos
Um ManagementObject que representa uma nova instância da classe WMI.A ManagementObject that represents a new instance of the WMI class.
Exemplos
O exemplo a seguir mostra como inicializar uma ManagementClass variável com um ManagementClass Construtor e, em seguida, criar uma nova instância de uma classe WMI.The following example shows how to initialize a ManagementClass variable with a ManagementClass constructor and then create a new instance of a WMI class.
using System;
using System.Management;
public class Sample
{
public static void Main()
{
ManagementClass envClass =
new ManagementClass("Win32_Environment");
ManagementObject newInstance =
envClass.CreateInstance();
newInstance["Name"] = "testEnvironmentVariable";
newInstance["VariableValue"] = "testValue";
newInstance["UserName"] = "<SYSTEM>";
newInstance.Put(); //to commit the new instance.
}
}
Imports System.Management
Class Sample
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
Dim envClass As New ManagementClass( _
"Win32_Environment")
Dim newInstance As ManagementObject
newInstance = envClass.CreateInstance()
newInstance("Name") = "testEnvironmentVariable"
newInstance("VariableValue") = "testValue"
newInstance("UserName") = "<SYSTEM>"
newInstance.Put() 'to commit the new instance.
End Function
End Class
Comentários
Observe que a nova instância não é confirmada até que o Put método () seja chamado.Note that the new instance is not committed until the Put() method is called. Antes de confirmá-lo, as propriedades de chave devem ser especificadas.Before committing it, the key properties must be specified.
Segurança do .NET Framework.NET Framework Security
Confiança total para o chamador imediato.Full trust for the immediate caller. Este membro não pode ser usado pelo código parcialmente confiável.This member cannot be used by partially trusted code. Para obter mais informações, consulte usando bibliotecas de código parcialmente confiável.For more information, see Using Libraries from Partially Trusted Code.