Udostępnij za pośrednictwem


Jak utworzyć rekord odnajdywania danych

Rekord odnajdywania danych (DDR) w Configuration Manager określa typ zasobu, proces odnajdywania, lokację, która odnalazła zasób, oraz właściwości zasobu. Configuration Manager udostępnia sześć funkcji biblioteki używanych do tworzenia własnych żądań DDR. Aby uzyskać więcej informacji. zobacz Informacje o tworzeniu rekordu odnajdywania danych.

Aby utworzyć rekord odnajdywania danych

  1. Utwórz nowe wystąpienie SMSResGen klasy.

  2. Utwórz nową trasę DDR przy użyciu NewDDR metody .

  3. Dodaj właściwości do trasy DDR przy użyciu ADDPROP_ metod.

  4. Zapisz nową trasę DDR do pliku przy użyciu DDRWrite metody .

Przykład

Poniższy przykład tworzy trasę DDR.


Sub CreateNewDDR()  

    ' Define constants.  
    Const ADDPROP_NONE  = &H0  
    Const ADDPROP_GUID  = &H2  
    Const ADDPROP_KEY   = &H8  
    Const ADDPROP_ARRAY = &H10  

    ' Define variables.  
    Dim newDDR  
    Dim siteCode  
    Dim computerName  
    Dim siteName  
    Dim newIPAddress(2), newIPSubnet(2), newMACAddress(2)  

    ' Load variables with values.  
    siteCode = "ABC"  
    computerName="ComputerName"  
    siteName="Active Directory Site Name"  
    newIPAddress(0)="123.234.12.23"  
    newIPAddress(1)="123.234.12.32"  
    newIPSubnet(0)="123.234.12.0"  
    newIPSubnet(1)="123.234.12.0"  
    newMACAddress(0)="00:02:A5:B1:11:68"  
    newMACAddress(1)="00:02:A5:B1:11:69"  

    ' Load an instance of the SMSResGen.dll.  
    Set newDDR=CreateObject("SMSResGen.SMSResGen.1")  

    ' Create a new DDR using the DDRNew method.  
    newDDR.DDRNew "System", "CustomAgent", siteCode  

    ' Add properties to the new DDR using the DDRAddString method and the previously defined variables.  
    newDDR.DDRAddString "NetBIOS Name", computerName, 64, ADDPROP_KEY  
    newDDR.DDRAddString "AD Site Name", siteName, 64, ADDPROP_NONE  

    ' Add properties to the new DDR using the DDRAddStringArray method and the previously defined variables.   
    newDDR.DDRAddStringArray "IP Addresses", Array(newIPAddress(0),newIPAddress(1)), 64, ADDPROP_ARRAY  
    newDDR.DDRAddStringArray "MAC Addresses", Array(newMACAddress(0),newMACAddress(1)), 64, ADDPROP_ARRAY OR ADDPROP_KEY  
    newDDR.DDRAddStringArray "IP Subnets", Array(newIPSubnet(0),newIPSubnet(1)), 64, ADDPROP_ARRAY  

    ' Write new DDR to file.  
    newDDR.DDRWrite "NewDDR.DDR"  
    wscript.echo "Created new DDR."  

End Sub  


public void CreateNewDDR()  
{  
    try  
    {            
        // Define and set the required variables.   
        string Computer = "ComputerName";  
        string SiteName = "Active Directory Site Name";  
        string[] IPAddress  = new string[] { "123.234.12.23", "123.234.12.32" };  
        string[] IPSubnet   = new string[] { "123.234.12.0", "123.234.12.0" };  
        string[] MACAddress = new string[] { "00:02:A5:B1:11:68", "00:02:A5:B1:11:68" };  
        string siteCode = "TQ1";  

        // Create the SMSResGenClass instance.  
        SMSRSGENCTLLib.SMSResGen newDDR = new SMSRSGENCTLLib.SMSResGen();  

        // Create a new DDR using the DDRNew method.  
        newDDR.DDRNew("System", "CustomAgent", siteCode);  

        // Add properties to the new DDR using the DDRAddString method and the previously defined variables.  
        newDDR.DDRAddString("NetBIOS Name", Computer, 64, SMSRSGENCTLLib.DDRPropertyFlagsEnum.ADDPROP_KEY);  
        newDDR.DDRAddString("AD Site Name", SiteName, 64, SMSRSGENCTLLib.DDRPropertyFlagsEnum.ADDPROP_NONE);  

        // Add properties to the new DDR using the DDRAddStringArray method and the previously defined variables.   
        newDDR.DDRAddStringArray("IP Subnets", IPAddress, 64, SMSRSGENCTLLib.DDRPropertyFlagsEnum.ADDPROP_ARRAY);  
        newDDR.DDRAddStringArray("MAC Addresses", MACAddress, 64, SMSRSGENCTLLib.DDRPropertyFlagsEnum.ADDPROP_ARRAY | SMSRSGENCTLLib.DDRPropertyFlagsEnum.ADDPROP_KEY);  
        newDDR.DDRAddStringArray("IP Subnets", IPSubnet, 64, SMSRSGENCTLLib.DDRPropertyFlagsEnum.ADDPROP_ARRAY);  

        // Write new DDR to file.  
        newDDR.DDRWrite("NewDDR.DDR");  
        Console.WriteLine("Created new DDR.");          
    }  
    catch (SmsException ex)  
    {  
        Console.WriteLine("Failed to create DDR. Error: " + ex.Message);  
        throw;  
    }  
}  

Kompilowanie kodu

Ważna

Te przykłady języków VBScript i C# wymagają odpowiednio smsrsgen.dll i smsrsgenctl.dll. Oba pliki są dołączone jako część zestawu SDK do pobrania Configuration Manager (w folderze "Redistributables").

Plik smsrsgenctl.dll jest 32-bitową biblioteką dll i musi zostać zarejestrowany w systemie, który będzie uruchamiał aplikację. Ponadto aplikacja używająca smsrsgenctl.dll powinna zostać skompilowana jako aplikacja x86.

Niezawodne programowanie

Aby uzyskać więcej informacji na temat obsługi błędów, zobacz Informacje o błędach Configuration Manager.

zabezpieczenia .NET Framework

Aby uzyskać więcej informacji na temat zabezpieczania aplikacji Configuration Manager, zobacz Configuration Manager administracja oparta na rolach.

Zobacz też

SMSResGen, klasa automatyzacji COM