Trying to connect me to another computer sends me "Connection failure".
I do not know if it's a credential error, but I sent a ping
to the computer and if it responds the same with remote connections.
This is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management;
namespace capaDatos
{
public class conexion
{
public ManagementScope ConectarWMI(string strBibliotecaWMI,bool blnHasDomain,
bool blnIsRemote, string strServer, string strUsername,
string strPassword, string strAuthority= null)
{
ManagementScope scope = new ManagementScope();
try
{
ConnectionOptions opciones = new ConnectionOptions();
opciones.EnablePrivileges = true;
opciones.Impersonation = ImpersonationLevel.Impersonate;
if (blnHasDomain == true)
{
opciones.Authority = string.Format(@"ntlmdomain:{0}", strAuthority);
}
if (blnIsRemote)
{
opciones.Username = strUsername;
opciones.Password = strPassword;
}
scope.Path.Path = string.Format(@"\{0}\root\{1}", strServer, strBibliotecaWMI);
Console.WriteLine(scope.Path.Path);
scope.Options = opciones;
scope.Connect();
if (scope.IsConnected) { Console.WriteLine("Conexion exitosa"); }
else { Console.WriteLine("Fallo de conexion"); }
}
catch(ManagementException me) { Console.WriteLine("ManagementException" + " ---> " + me.Message); }
catch (Exception ex ) { Console.WriteLine("Exception" + " : " + ex.Message); }
return scope;
}
}
}
--------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using capaDatos;
using System.Management;
namespace capaNegocio
{
public class AccesoWMI
{
public void Pruebas()
{
WMI c = new WMI();
c.ToGet_Win32_NetworkAdapter();
}
public void pruebasRemotas()
{
conexion cone = new conexion();
cone.ConectarWMI("cimv2", false, true, "JohnnyDroop", "Dogy", "pandora864", null);
}
}
}
-------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using capaNegocio;
namespace dgtsi_pruebas
{
class Program
{
static void Main(string[] args)
{
AccesoWMI w = new AccesoWMI();
//w.Pruebas();
w.pruebasRemotas();
Console.ReadLine();
}
}
}