Beispiel #1
0
        private ManagementScope CreateManagementScope()
        {
            try
            {
                ManagementScope Scope = null;

                if (NetworkHelper.IsLocalAddress(Address))
                {
                    Logger.Info(string.Format("Creating management scope to local host '{0}'", Address));

                    var Path = new ManagementPath();
                    Path.Server        = "";
                    Path.NamespacePath = @"\root\cimv2";
                    Scope = new ManagementScope(Path);
                }
                else
                {
                    Logger.Info(string.Format("Creating management scope to remote machine '{0}'", Address));

                    var Connection = new ConnectionOptions();
                    Connection.Username = Username;
                    Connection.Password = Password;
                    Scope = new ManagementScope(string.Format(@"\\{0}\root\cimv2", Address), Connection);
                }

                Scope.Connect();

                return(Scope);
            }
            catch (Exception e)
            {
                Logger.Error(string.Format("Failed to create Windows management scope for device '{0}'. {1}", Address, e.Message));
            }

            return(null);
        }
 public override bool Ping()
 {
     return(NetworkHelper.PingDevice(Address, Logger));
 }