Megosztás a következőn keresztül:


MOF-fájl importálása a leltár bővítéséhez

Egy MOF-fájlt importál a leltár Configuration Manager való kiterjesztéséhez a ImportInventoryReport metódussal.

MOF-fájl importálása a hardverleltár bővítéséhez

  1. Csatlakozzon a helykiszolgáló névteréhez (root\sms\site_<site kód>).

  2. Szerezze be a SMS_InventoryReport osztályt.

  3. Hívja meg az ImportInventoryReport metódust, és adja meg az InventoryReportID, az ImportType és az MofBuffer paramétereket.

Példa

Az alábbi példa egy MOF-fájlt importál a leltár ImportInventoryReport metódussal történő kibővítéséhez.


public class ImportInventory{            public const string HardwareInventoryReportID = "{00000000-0000-0000-0000-000000000001}";    static void Main(string[] args)    {        if (args != null && args.Length >= 2)        {            string fileName = args[0];            string siteCode = args[1];            ImportInventoryReport(siteCode, fileName);        }        else        {            Console.WriteLine("Usage: InventoryImportExample <MofFileName> <site code>");        }        Console.WriteLine("Press any key to exit");        Console.ReadLine();    }    public static void ImportInventoryReport(string siteCode, string fileName,         string inventoryReportID = HardwareInventoryReportID,         InventoryImportType importOption = InventoryImportType.BothClassAndReport)    {        if (File.Exists(fileName)==false)        {            throw new FileNotFoundException("MOF file not found", fileName);        }        string mofToImport = File.ReadAllText(fileName);        // Get the SMS_InventoryReport class.        try        {            string scope = string.Format(@"root\sms\site_{0}",siteCode);            ManagementClass cls = new ManagementClass(scope, "SMS_InventoryReport", null);            ManagementBaseObject inParams = cls.GetMethodParameters("ImportInventoryReport");            inParams["InventoryReportID"] = inventoryReportID;            inParams["ImportType"] = (uint)importOption;            inParams["MofBuffer"] = mofToImport;            ManagementBaseObject retVal = cls.InvokeMethod("ImportInventoryReport", inParams, null);            // Get current site code.            uint resultCode = (uint)retVal["StatusCode"];            if (resultCode == 0)            {                Console.WriteLine("ImportInventoryReport for file {0} succeed ", fileName);            }            else            {                Console.WriteLine("ImportInventoryReport for file {0} failed with error code:{1} ", fileName,resultCode);            }        }        catch (ManagementException e)        {            Console.WriteLine("Failed to execute method ImportInventoryReport for file {0}: {1}", fileName, e.ToString());        }    }    public enum InventoryImportType    {        ClassOnly = 1,         ReportOnly = 2,         BothClassAndReport = 3    }}  

An example MOF file.================================[ SMS_Report (TRUE),  SMS_Group_Name ("User Account"),  SMS_Class_ID ("MICROSOFT|USER_ACCOUNT|1.0"),  Namespace ("root\\\\cimv2") ]class Win32_UserAccount : SMS_Class_Template{    [ SMS_Report (TRUE), key ]    String     Domain;    [ SMS_Report (TRUE), key ]    String     Name;    [ SMS_Report (TRUE) ]    UInt32     AccountType;    [ SMS_Report (TRUE) ]    String     Caption;    [ SMS_Report (TRUE) ]    String     Description;    [ SMS_Report (TRUE) ]    Boolean     Disabled;    [ SMS_Report (TRUE) ]    String     FullName;    [ SMS_Report (TRUE) ]    DateTime     InstallDate;    [ SMS_Report (TRUE) ]    Boolean     LocalAccount;    [ SMS_Report (TRUE) ]    Boolean     Lockout;    [ SMS_Report (TRUE) ]    Boolean     PasswordChangeable;    [ SMS_Report (TRUE) ]    Boolean     PasswordExpires;    [ SMS_Report (TRUE) ]    Boolean     PasswordRequired;    [ SMS_Report (TRUE) ]    String     SID;    [ SMS_Report (TRUE) ]    UInt8     SIDType;    [ SMS_Report (TRUE) ]    String     Status;};  

A példametódus a következő paraméterekkel rendelkezik:

Paraméter Típus Leírás
siteCode -Kezelt: String A helykód.
fileName -Kezelt: String Az importálandó MOF-fájl neve.
inventoryReportID -Kezelt: String Leltárjelentés azonosítója.
importOption -Kezelt: String Importálás típusa. A lehetséges értékek a következők:

– 1 – Csak osztály
– 2 – Csak jelentés
– 3 – Osztály és jelentés
mofToImport -Kezelt: String Az importálandó leltárosztályt vagy jelentést tartalmazó MOF-tartalom. Ez ugyanaz a formátum, mint a Configuration Manager 2007 sms_def.mof fájl, vagy a leltárügyfél beállításaiból exportált fájlformátum.

A kód fordítása

Ehhez a C#-példához a következőre van szükség:

Összeszerelés

System.Management

Robusztus programozás

A hibakezeléssel kapcsolatos további információkért lásd: A Configuration Manager hibák ismertetése.

.NET-keretrendszer Security

A Configuration Manager alkalmazások biztonságossá tételével kapcsolatos további információkért lásd: Configuration Manager szerepköralapú felügyelet.

Lásd még

Configuration Manager Software Development Kit
A Configuration Manager Inventory ismertetése