public MainWindow() { InitializeComponent(); locator = new WbemLocator(); WindowState = WindowState.Maximized; PopulateClassNavigator("root"); }
/// <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; } } } }
public void Initialize() { locator = new WbemLocator(); }