コード例 #1
0
        /// <summary>
        /// Establishes a connection to the WMI server and namespace.
        /// </summary>
        #endregion
        public void Open()
        {
            if (this.isDisposed)
            {
                throw new ObjectDisposedException(typeof(WmiConnection).FullName);
            }

            if (!this.isConnected)
            {
                IWbemLocator locator = new WbemLocator();

                lock (this.connectLockObject)
                {
                    if (!this.isConnected)
                    {
                        AuthenticationLevel authLevel = this.options.EnablePackageEncryption ? AuthenticationLevel.PacketIntegrity : AuthenticationLevel.PacketPrivacy;

                        if (this.IsRemote)
                        {
                            try
                            {
                                this.wbemServices = locator.ConnectServer(this.path, this.credential.UserName, this.credential.Password, null, WbemConnectOption.None, this.Authority, this.context);
                                this.wbemServices.SetProxy(this.credential.UserName, this.credential.Password, this.Authority, ImpersonationLevel.Impersonate, authLevel);
                            }
                            catch (LocalCredentialsException)
                            {
                                // try again without credential
                                this.ignoreCredential = true;
                                this.Open();
                                return; // exit method
                            }
                        }
                        else
                        {
                            this.wbemServices = locator.ConnectServer(this.path, null, null, null, WbemConnectOption.None, null, this.context);
                            this.wbemServices.SetProxy(ImpersonationLevel.Impersonate, authLevel);
                        }

                        this.isConnected = true;
                    }
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// This method populates the ClassNavigator treeview with all the WMI classes belonging to the specified namespace.
 /// </summary>
 /// <param name="nameSpace">The namespace to retrieve the classes from.</param>
 private void PopulateClassNavigator(string nameSpace)
 {
     try {
         service = locator.ConnectServer(".", nameSpace);
         IEnumerable <WbemObject> objects = service.GetAllObjects();
         ClassNavigator.PopulateTreeView(objects);
     } catch (ManagementException me) {
         TextBlockErrors.Text = me.Message;
     } catch (ArgumentException ae) {
         TextBlockErrors.Text = ae.Message;
     }
 }
コード例 #3
0
        public void CorrectNamespaceReturnsSWbemServiceObject()
        {
            WbemService service = locator.ConnectServer(localServer, rootcimv2);

            Assert.IsNotNull(service);
        }