Пример #1
0
        public static void Main()
        {
            bool       hasComputerNameChanged = true;
            CimSession cimSession             = null;
            string     className    = null;
            string     computerName = GetName("ComputerName");

            if (String.IsNullOrEmpty(computerName))
            {
                computerName = null;
            }

            string           namespaceName    = GetName("Namespace");
            CurrentOperation currentOperation = GetCurrentOption(true);

            while (true)
            {
                if (currentOperation == CurrentOperation.OperationQuit)
                {
                    if (cimSession != null)
                    {
                        cimSession.Close();
                        cimSession = null;
                    }

                    return;
                }

                if (ClassNeeded(currentOperation))
                {
                    className = GetName("ClassName");
                }

                try
                {
                    // Create local CIM session
                    if (hasComputerNameChanged)
                    {
                        if (cimSession != null)
                        {
                            cimSession.Close();
                        }

                        WMIDCOMCimSessionOptions sessionOptions = new WMIDCOMCimSessionOptions();

                        cimSession             = CimSession.Create(computerName, sessionOptions);
                        hasComputerNameChanged = false;
                    }

                    switch (currentOperation)
                    {
                    case CurrentOperation.EnumerateAsync:
                        SampleCimOperation.EnumerateASync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.EnumerateSync:
                        SampleCimOperation.EnumerateSync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.GetInstanceSync:
                        SampleCimOperation.GetInstanceSync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.GetInstanceAsync:
                        SampleCimOperation.GetInstanceASync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.CreateInstanceAsync:
                        SampleCimOperation.CreateInstanceASync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.CreateInstanceSync:
                        SampleCimOperation.CreateInstanceSync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.DeleteInstanceAsync:
                        SampleCimOperation.DeleteInstanceASync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.DeleteInstanceSync:
                        SampleCimOperation.DeleteInstanceSync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.ModifyInstanceAsync:
                        SampleCimOperation.ModifyInstanceASync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.ModifyInstanceSync:
                        SampleCimOperation.ModifyInstanceSync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.QueryInstanceAsync:
                        SampleCimOperation.QueryInstanceASync(cimSession, namespaceName);
                        break;

                    case CurrentOperation.QueryInstanceSync:
                        SampleCimOperation.QueryInstanceSync(cimSession, namespaceName);
                        break;

                    case CurrentOperation.QueryAssociationSync:
                        SampleCimOperation.EnumerateAssociatedInstanceSync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.QueryAssociationAsync:
                        SampleCimOperation.EnumerateAssociatedInstanceASync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.InvokeMethodSync:
                        SampleCimOperation.InvokeMethodSync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.InvokeMethodAsync:
                        SampleCimOperation.InvokeMethodASync(cimSession, namespaceName, className);
                        break;

                    case CurrentOperation.SubscribeSync:
                        SampleCimOperation.SubscribeSync(cimSession, namespaceName);
                        break;

                    case CurrentOperation.SubscribeAsync:
                        SampleCimOperation.SubscribeASync(cimSession, namespaceName);
                        break;

                    case CurrentOperation.OperationComputerName:
                        computerName = GetName("ComputerName");
                        if (String.IsNullOrEmpty(computerName))
                        {
                            computerName = null;
                        }

                        hasComputerNameChanged = true;
                        break;

                    case CurrentOperation.OperationNamespaceName:
                        namespaceName = GetName("Namespace");
                        break;

                    default:
                        break;
                    }
                }
                catch (CimException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                currentOperation = GetCurrentOption(false);
            }
        }
Пример #2
0
        public static void Main()
        {
            bool hasComputerNameChanged = true;
            CimSession cimSession = null;
            string className = null;
            string computerName = GetName("ComputerName");
            if (String.IsNullOrEmpty(computerName))
            {
                computerName = null;
            }

            string namespaceName = GetName("Namespace");
            CurrentOperation currentOperation = GetCurrentOption(true);
            while (true)
            {
                if (currentOperation == CurrentOperation.OperationQuit)
                {
                    if (cimSession != null)
                    {
                        cimSession.Close();
                        cimSession = null;
                    }

                    return;
                }

                if (ClassNeeded(currentOperation))
                {
                    className = GetName("ClassName");
                }

                try
                {
                    // Create local CIM session
                    if (hasComputerNameChanged)
                    {
                        if (cimSession != null)
                        {
                            cimSession.Close();
                        }

                        WMIDCOMCimSessionOptions sessionOptions=new WMIDCOMCimSessionOptions();

                        cimSession = CimSession.Create(computerName, sessionOptions);
                        hasComputerNameChanged = false;
                    }

                    switch (currentOperation)
                    {
                        case CurrentOperation.EnumerateAsync:
                            SampleCimOperation.EnumerateASync(cimSession, namespaceName, className);
                            break;
                        case CurrentOperation.EnumerateSync:
                            SampleCimOperation.EnumerateSync(cimSession, namespaceName, className);
                            break;
                        case CurrentOperation.GetInstanceSync:
                            SampleCimOperation.GetInstanceSync(cimSession, namespaceName, className);
                            break;
                        case CurrentOperation.GetInstanceAsync:
                            SampleCimOperation.GetInstanceASync(cimSession, namespaceName, className);
                            break;
                        case CurrentOperation.CreateInstanceAsync:
                            SampleCimOperation.CreateInstanceASync(cimSession, namespaceName, className);
                            break;
                        case CurrentOperation.CreateInstanceSync:
                            SampleCimOperation.CreateInstanceSync(cimSession, namespaceName, className);
                            break;
                        case CurrentOperation.DeleteInstanceAsync:
                            SampleCimOperation.DeleteInstanceASync(cimSession, namespaceName, className);
                            break;
                        case CurrentOperation.DeleteInstanceSync:
                            SampleCimOperation.DeleteInstanceSync(cimSession, namespaceName, className);
                            break;
                        case CurrentOperation.ModifyInstanceAsync:
                            SampleCimOperation.ModifyInstanceASync(cimSession, namespaceName, className);
                            break;
                        case CurrentOperation.ModifyInstanceSync:
                            SampleCimOperation.ModifyInstanceSync(cimSession, namespaceName, className);
                            break;
                        case CurrentOperation.QueryInstanceAsync:
                            SampleCimOperation.QueryInstanceASync(cimSession, namespaceName);
                            break;
                        case CurrentOperation.QueryInstanceSync:
                            SampleCimOperation.QueryInstanceSync(cimSession, namespaceName);
                            break;
                        case CurrentOperation.QueryAssociationSync:
                            SampleCimOperation.EnumerateAssociatedInstanceSync(cimSession, namespaceName, className);
                            break;
                        case CurrentOperation.QueryAssociationAsync:
                            SampleCimOperation.EnumerateAssociatedInstanceASync(cimSession, namespaceName, className);
                            break;
                        case CurrentOperation.InvokeMethodSync:
                            SampleCimOperation.InvokeMethodSync(cimSession, namespaceName, className);
                            break;
                        case CurrentOperation.InvokeMethodAsync:
                            SampleCimOperation.InvokeMethodASync(cimSession, namespaceName, className);
                            break;
                        case CurrentOperation.SubscribeSync:
                            SampleCimOperation.SubscribeSync(cimSession, namespaceName);
                            break;
                        case CurrentOperation.SubscribeAsync:
                            SampleCimOperation.SubscribeASync(cimSession, namespaceName);
                            break;
                        case CurrentOperation.OperationComputerName:
                            computerName = GetName("ComputerName");
                            if (String.IsNullOrEmpty(computerName))
                            {
                                computerName = null;
                            }

                            hasComputerNameChanged = true;
                            break;
                        case CurrentOperation.OperationNamespaceName:
                            namespaceName = GetName("Namespace");
                            break;
                        default:
                            break;
                    }
                }
                catch (CimException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                currentOperation = GetCurrentOption(false);
            }
        }