Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: xkiz ™ en 12 Septiembre 2010, 11:58 am



Título: habilitar o deshabilitar adaptador de red [Win32_NetworkAdapter]
Publicado por: xkiz ™ en 12 Septiembre 2010, 11:58 am
bue, + o - como dice el titulo estoy tratando de habilitar o deshabilitar la conexion de area local, para ello, buscando por Google
encontre esto (http://msdn.microsoft.com/en-us/library/aa394216%28v=VS.85%29.aspx) lo cual despues de transcribirlo en vb6, no puedo hacer que funcionen las 2 alternativas [ Enable / Disable ].
Aca dejo lo que tengo hasta ahora:

Código
  1. Private Enum What
  2.    Disable = 0
  3.    Enable = 1
  4. End Enum
  5.  
  6. Private Function zarazaConAdaptor(SoWhat As What) As Boolean
  7. Dim objWMIService As Object
  8. Dim colAdapters As Object
  9. Dim Adapter As Object
  10. Dim errReturn As Integer
  11.  
  12. On Error GoTo Ups
  13.  
  14. Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
  15. Set colAdapters = objWMIService.Execquery("Select * from Win32_NetworkAdapter Where NetEnabled=True")
  16.  
  17. 'For Each Adapter In colAdapters
  18. '    Debug.Print Adapter.DeviceId & " " & Adapter.Name
  19. 'Next
  20. If SoWhat = Disable Then errReturn = colAdapters.ItemIndex(0).Disable()
  21. If SoWhat = Enable Then errReturn = colAdapters.ItemIndex(0).Enable()
  22.  
  23. If (errReturn <> 0) Then
  24.    zarazaConAdaptor = False
  25. Else
  26.    zarazaConAdaptor = True
  27. End If
  28.  
  29. Set objWMIService = Nothing
  30. Set colAdapters = Nothing
  31. Exit Function
  32. Ups:
  33. zarazaConAdaptor = False
  34. Set objWMIService = Nothing
  35. Set colAdapters = Nothing
  36. End Function
  37.  
  38. Private Sub Command1_Click()
  39. 'Debug.Print zarazaConAdaptor(Disable)
  40. Debug.Print zarazaConAdaptor(Enable)
  41. End Sub
  42.  

no logro darme cuenta como solucionar el errror

Citar
Verdadero
-2147217400 Parámetro no válido

¿alguien conoce otra forma de hacer esto? mediante API o algo similar me seria mejor por que usar wmi no me convence mucho....


Título: Re: habilitar o deshabilitar adaptador de red [Win32_NetworkAdapter]
Publicado por: xkiz ™ en 12 Septiembre 2010, 12:06 pm
jejeje me respongo a mi mismo,, me di cuenta donde estaba el error.

Código
  1. Set colAdapters = objWMIService.Execquery("Select * from Win32_NetworkAdapter Where NetEnabled=True")

 antes ni vi lo de " Where NetEnabled=True"
bueno igual ¿alguien sabe otra forma de hacer esto mismo?


Título: Re: habilitar o deshabilitar adaptador de red [Win32_NetworkAdapter]
Publicado por: Dessa en 12 Septiembre 2010, 13:29 pm
Mirá si esto puede llegar a servir

http://support.microsoft.com/kb/304296/es (http://support.microsoft.com/kb/304296/es)






Título: Re: habilitar o deshabilitar adaptador de red [Win32_NetworkAdapter]
Publicado por: skapunky en 12 Septiembre 2010, 15:15 pm
Hay una forma de hacerlo mucho mas rapida (pero mas cutre). Modifica el registro de windows para habilitar/deshabilitar. La clave a mirar si no estoy equivocado es:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces