Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement