Exemplo n.º 1
0
        internal ManagementPath SetWmiInstanceBuildManagementPath()
        {
            ManagementPath managementPath = null;

            if (base.GetType() == typeof(SetWmiInstance))
            {
                SetWmiInstance setWmiInstance = (SetWmiInstance)this;
                if (setWmiInstance.Class == null)
                {
                    managementPath = new ManagementPath(setWmiInstance.Path);
                    if (!string.IsNullOrEmpty(managementPath.NamespacePath))
                    {
                        if (setWmiInstance.namespaceSpecified)
                        {
                            base.ThrowTerminatingError(new ErrorRecord(new InvalidOperationException(), "NamespaceSpecifiedWithPath", ErrorCategory.InvalidOperation, setWmiInstance.Namespace));
                        }
                    }
                    else
                    {
                        managementPath.NamespacePath = setWmiInstance.Namespace;
                    }
                    if (managementPath.Server != "." && setWmiInstance.serverNameSpecified)
                    {
                        base.ThrowTerminatingError(new ErrorRecord(new InvalidOperationException(), "ComputerNameSpecifiedWithPath", ErrorCategory.InvalidOperation, setWmiInstance.ComputerName));
                    }
                    if (!managementPath.IsClass)
                    {
                        if (!setWmiInstance.flagSpecified)
                        {
                            setWmiInstance.PutType = PutType.UpdateOrCreate;
                        }
                        else
                        {
                            if (setWmiInstance.PutType != PutType.UpdateOnly && setWmiInstance.PutType != PutType.UpdateOrCreate)
                            {
                                base.ThrowTerminatingError(new ErrorRecord(new InvalidOperationException(), "NonUpdateFlagSpecifiedWithInstancePath", ErrorCategory.InvalidOperation, (object)setWmiInstance.PutType));
                            }
                        }
                    }
                    else
                    {
                        if (setWmiInstance.flagSpecified && setWmiInstance.PutType != PutType.CreateOnly)
                        {
                            base.ThrowTerminatingError(new ErrorRecord(new InvalidOperationException(), "CreateOnlyFlagNotSpecifiedWithClassPath", ErrorCategory.InvalidOperation, (object)setWmiInstance.PutType));
                        }
                        setWmiInstance.PutType = PutType.CreateOnly;
                    }
                }
                else
                {
                    if (setWmiInstance.flagSpecified && setWmiInstance.PutType != PutType.CreateOnly)
                    {
                        base.ThrowTerminatingError(new ErrorRecord(new InvalidOperationException(), "CreateOnlyFlagNotSpecifiedWithClassPath", ErrorCategory.InvalidOperation, (object)setWmiInstance.PutType));
                    }
                    setWmiInstance.PutType = PutType.CreateOnly;
                }
            }
            return(managementPath);
        }
Exemplo n.º 2
0
        internal ManagementObject SetWmiInstanceGetPipelineObject()
        {
            ManagementObject value = null;

            if (base.GetType() == typeof(SetWmiInstance))
            {
                SetWmiInstance setWmiInstance = (SetWmiInstance)this;
                if (setWmiInstance.InputObject != null)
                {
                    if (setWmiInstance.InputObject.GetType() != typeof(ManagementClass))
                    {
                        if (!setWmiInstance.flagSpecified)
                        {
                            setWmiInstance.PutType = PutType.UpdateOrCreate;
                        }
                        else
                        {
                            if (setWmiInstance.PutType != PutType.UpdateOnly && setWmiInstance.PutType != PutType.UpdateOrCreate)
                            {
                                base.ThrowTerminatingError(new ErrorRecord(new InvalidOperationException(), "NonUpdateFlagSpecifiedWithInstancePath", ErrorCategory.InvalidOperation, (object)setWmiInstance.PutType));
                            }
                        }
                        value = (ManagementObject)setWmiInstance.InputObject.Clone();
                    }
                    else
                    {
                        if (setWmiInstance.flagSpecified && setWmiInstance.PutType != PutType.CreateOnly)
                        {
                            base.ThrowTerminatingError(new ErrorRecord(new InvalidOperationException(), "CreateOnlyFlagNotSpecifiedWithClassPath", ErrorCategory.InvalidOperation, (object)setWmiInstance.PutType));
                        }
                        value = ((ManagementClass)setWmiInstance.InputObject).CreateInstance();
                        setWmiInstance.PutType = PutType.CreateOnly;
                    }
                    if (setWmiInstance.Arguments != null)
                    {
                        IDictionaryEnumerator enumerator = setWmiInstance.Arguments.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            value[enumerator.Key as string] = enumerator.Value;
                        }
                    }
                }
            }
            return(value);
        }
Exemplo n.º 3
0
        internal ManagementObject SetWmiInstanceGetObject(ManagementPath mPath, string serverName)
        {
            ConnectionOptions connectionOption = this.GetConnectionOption();
            ManagementObject  value            = null;

            if (base.GetType() == typeof(SetWmiInstance))
            {
                SetWmiInstance setWmiInstance = (SetWmiInstance)this;
                if (setWmiInstance.Path == null)
                {
                    ManagementScope managementScope = new ManagementScope(WMIHelper.GetScopeString(serverName, setWmiInstance.Namespace), connectionOption);
                    ManagementClass managementClass = new ManagementClass(setWmiInstance.Class);
                    managementClass.Scope = managementScope;
                    value = managementClass.CreateInstance();
                }
                else
                {
                    mPath.Server = serverName;
                    ManagementScope managementScope1 = new ManagementScope(mPath, connectionOption);
                    if (!mPath.IsClass)
                    {
                        ManagementObject managementObject = new ManagementObject(mPath);
                        managementObject.Scope = managementScope1;
                        try
                        {
                            managementObject.Get();
                        }
                        catch (ManagementException managementException1)
                        {
                            ManagementException managementException = managementException1;
                            if (managementException.ErrorCode == ManagementStatus.NotFound)
                            {
                                int num = setWmiInstance.Path.IndexOf(':');
                                if (num != -1)
                                {
                                    int num1 = setWmiInstance.Path.Substring(num).IndexOf('.');
                                    if (num1 != -1)
                                    {
                                        string          str              = setWmiInstance.Path.Substring(0, num1 + num);
                                        ManagementPath  managementPath   = new ManagementPath(str);
                                        ManagementClass managementClass1 = new ManagementClass(managementPath);
                                        managementClass1.Scope = managementScope1;
                                        managementObject       = managementClass1.CreateInstance();
                                    }
                                    else
                                    {
                                        throw;
                                    }
                                }
                                else
                                {
                                    throw;
                                }
                            }
                            else
                            {
                                throw;
                            }
                        }
                        value = managementObject;
                    }
                    else
                    {
                        ManagementClass managementClass2 = new ManagementClass(mPath);
                        managementClass2.Scope = managementScope1;
                        value = managementClass2.CreateInstance();
                    }
                }
                if (setWmiInstance.Arguments != null)
                {
                    IDictionaryEnumerator enumerator = setWmiInstance.Arguments.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        value[enumerator.Key as string] = enumerator.Value;
                    }
                }
            }
            return(value);
        }
Exemplo n.º 4
0
        private void ConnectSetWmi()
        {
            ManagementObject value;
            SetWmiInstance   setWmiInstance = (SetWmiInstance)this.wmiObject;

            this.state = WmiState.Running;
            this.RaiseWmiOperationState(null, WmiState.Running);
            if (setWmiInstance.InputObject == null)
            {
                ManagementPath managementPath = null;
                if (setWmiInstance.Class == null)
                {
                    managementPath = new ManagementPath(setWmiInstance.Path);
                    if (!string.IsNullOrEmpty(managementPath.NamespacePath))
                    {
                        if (setWmiInstance.namespaceSpecified)
                        {
                            InvalidOperationException invalidOperationException = new InvalidOperationException("NamespaceSpecifiedWithPath");
                            this.internalException = invalidOperationException;
                            this.state             = WmiState.Failed;
                            this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                            return;
                        }
                    }
                    else
                    {
                        managementPath.NamespacePath = setWmiInstance.Namespace;
                    }
                    if (!(managementPath.Server != ".") || !setWmiInstance.serverNameSpecified)
                    {
                        if (!managementPath.IsClass)
                        {
                            if (!setWmiInstance.flagSpecified)
                            {
                                setWmiInstance.PutType = PutType.UpdateOrCreate;
                            }
                            else
                            {
                                if (setWmiInstance.PutType != PutType.UpdateOnly && setWmiInstance.PutType != PutType.UpdateOrCreate)
                                {
                                    InvalidOperationException invalidOperationException1 = new InvalidOperationException("NonUpdateFlagSpecifiedWithInstancePath");
                                    this.internalException = invalidOperationException1;
                                    this.state             = WmiState.Failed;
                                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                                    return;
                                }
                            }
                        }
                        else
                        {
                            if (!setWmiInstance.flagSpecified || setWmiInstance.PutType == PutType.CreateOnly)
                            {
                                setWmiInstance.PutType = PutType.CreateOnly;
                            }
                            else
                            {
                                InvalidOperationException invalidOperationException2 = new InvalidOperationException("CreateOnlyFlagNotSpecifiedWithClassPath");
                                this.internalException = invalidOperationException2;
                                this.state             = WmiState.Failed;
                                this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                                return;
                            }
                        }
                    }
                    else
                    {
                        InvalidOperationException invalidOperationException3 = new InvalidOperationException("ComputerNameSpecifiedWithPath");
                        this.internalException = invalidOperationException3;
                        this.state             = WmiState.Failed;
                        this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                        return;
                    }
                }
                else
                {
                    if (setWmiInstance.flagSpecified && setWmiInstance.PutType != PutType.CreateOnly)
                    {
                        InvalidOperationException invalidOperationException4 = new InvalidOperationException("CreateOnlyFlagNotSpecifiedWithClassPath");
                        this.internalException = invalidOperationException4;
                        this.state             = WmiState.Failed;
                        this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                        return;
                    }
                    setWmiInstance.PutType = PutType.CreateOnly;
                }
                if (managementPath != null && (!(managementPath.Server == ".") || !setWmiInstance.serverNameSpecified))
                {
                    this.computerName = managementPath.Server;
                }
                ConnectionOptions connectionOption = setWmiInstance.GetConnectionOption();
                try
                {
                    if (setWmiInstance.Path == null)
                    {
                        ManagementScope managementScope = new ManagementScope(WMIHelper.GetScopeString(this.computerName, setWmiInstance.Namespace), connectionOption);
                        ManagementClass managementClass = new ManagementClass(setWmiInstance.Class);
                        managementClass.Scope = managementScope;
                        value = managementClass.CreateInstance();
                    }
                    else
                    {
                        managementPath.Server = this.computerName;
                        ManagementScope managementScope1 = new ManagementScope(managementPath, connectionOption);
                        if (!managementPath.IsClass)
                        {
                            ManagementObject managementObject = new ManagementObject(managementPath);
                            managementObject.Scope = managementScope1;
                            try
                            {
                                managementObject.Get();
                            }
                            catch (ManagementException managementException1)
                            {
                                ManagementException managementException = managementException1;
                                if (managementException.ErrorCode == ManagementStatus.NotFound)
                                {
                                    int num = setWmiInstance.Path.IndexOf(':');
                                    if (num != -1)
                                    {
                                        int num1 = setWmiInstance.Path.Substring(num).IndexOf('.');
                                        if (num1 != -1)
                                        {
                                            string          str              = setWmiInstance.Path.Substring(0, num1 + num);
                                            ManagementPath  managementPath1  = new ManagementPath(str);
                                            ManagementClass managementClass1 = new ManagementClass(managementPath1);
                                            managementClass1.Scope = managementScope1;
                                            managementObject       = managementClass1.CreateInstance();
                                        }
                                        else
                                        {
                                            this.internalException = managementException;
                                            this.state             = WmiState.Failed;
                                            this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        this.internalException = managementException;
                                        this.state             = WmiState.Failed;
                                        this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                                        return;
                                    }
                                }
                                else
                                {
                                    this.internalException = managementException;
                                    this.state             = WmiState.Failed;
                                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                                    return;
                                }
                            }
                            value = managementObject;
                        }
                        else
                        {
                            ManagementClass managementClass2 = new ManagementClass(managementPath);
                            managementClass2.Scope = managementScope1;
                            value = managementClass2.CreateInstance();
                        }
                    }
                    if (setWmiInstance.Arguments != null)
                    {
                        IDictionaryEnumerator enumerator = setWmiInstance.Arguments.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            value[enumerator.Key as string] = enumerator.Value;
                        }
                    }
                    PutOptions putOption = new PutOptions();
                    putOption.Type = setWmiInstance.PutType;
                    if (value == null)
                    {
                        InvalidOperationException invalidOperationException5 = new InvalidOperationException();
                        this.internalException = invalidOperationException5;
                        this.state             = WmiState.Failed;
                        this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                    }
                    else
                    {
                        value.Put(this.results, putOption);
                    }
                }
                catch (ManagementException managementException3)
                {
                    ManagementException managementException2 = managementException3;
                    this.internalException = managementException2;
                    this.state             = WmiState.Failed;
                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                }
                catch (COMException cOMException1)
                {
                    COMException cOMException = cOMException1;
                    this.internalException = cOMException;
                    this.state             = WmiState.Failed;
                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                }
                catch (UnauthorizedAccessException unauthorizedAccessException1)
                {
                    UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
                    this.internalException = unauthorizedAccessException;
                    this.state             = WmiState.Failed;
                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                }
            }
            else
            {
                ManagementObject value1 = null;
                try
                {
                    PutOptions putType = new PutOptions();
                    if (setWmiInstance.InputObject.GetType() != typeof(ManagementClass))
                    {
                        if (!setWmiInstance.flagSpecified)
                        {
                            setWmiInstance.PutType = PutType.UpdateOrCreate;
                        }
                        else
                        {
                            if (setWmiInstance.PutType != PutType.UpdateOnly && setWmiInstance.PutType != PutType.UpdateOrCreate)
                            {
                                InvalidOperationException invalidOperationException6 = new InvalidOperationException("NonUpdateFlagSpecifiedWithInstancePath");
                                this.internalException = invalidOperationException6;
                                this.state             = WmiState.Failed;
                                this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                                return;
                            }
                        }
                        value1 = (ManagementObject)setWmiInstance.InputObject.Clone();
                    }
                    else
                    {
                        if (!setWmiInstance.flagSpecified || setWmiInstance.PutType == PutType.CreateOnly)
                        {
                            value1 = ((ManagementClass)setWmiInstance.InputObject).CreateInstance();
                            setWmiInstance.PutType = PutType.CreateOnly;
                        }
                        else
                        {
                            InvalidOperationException invalidOperationException7 = new InvalidOperationException("CreateOnlyFlagNotSpecifiedWithClassPath");
                            this.internalException = invalidOperationException7;
                            this.state             = WmiState.Failed;
                            this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                            return;
                        }
                    }
                    if (setWmiInstance.Arguments != null)
                    {
                        IDictionaryEnumerator dictionaryEnumerator = setWmiInstance.Arguments.GetEnumerator();
                        while (dictionaryEnumerator.MoveNext())
                        {
                            value1[dictionaryEnumerator.Key as string] = dictionaryEnumerator.Value;
                        }
                    }
                    putType.Type = setWmiInstance.PutType;
                    if (value1 == null)
                    {
                        InvalidOperationException invalidOperationException8 = new InvalidOperationException();
                        this.internalException = invalidOperationException8;
                        this.state             = WmiState.Failed;
                        this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                    }
                    else
                    {
                        value1.Put(this.results, putType);
                    }
                }
                catch (ManagementException managementException5)
                {
                    ManagementException managementException4 = managementException5;
                    this.internalException = managementException4;
                    this.state             = WmiState.Failed;
                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                }
                catch (COMException cOMException3)
                {
                    COMException cOMException2 = cOMException3;
                    this.internalException = cOMException2;
                    this.state             = WmiState.Failed;
                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                }
                catch (UnauthorizedAccessException unauthorizedAccessException3)
                {
                    UnauthorizedAccessException unauthorizedAccessException2 = unauthorizedAccessException3;
                    this.internalException = unauthorizedAccessException2;
                    this.state             = WmiState.Failed;
                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                }
            }
        }