コード例 #1
0
        public MainWindow()
        {
            InitializeComponent();

            locator     = new WbemLocator();
            WindowState = WindowState.Maximized;

            PopulateClassNavigator("root");
        }
コード例 #2
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;
                    }
                }
            }
        }
コード例 #3
0
 public void Initialize()
 {
     locator = new WbemLocator();
 }