comment
IRC Chat
play_arrow
Este sitio utiliza cookies propias y de terceros. Si continúa navegando consideramos que acepta el uso de cookies. OK Más Información.

Api net send

  • 0 Respuestas
  • 1297 Vistas

0 Usuarios y 1 Visitante están viendo este tema.

Conectado ANTRAX

  • *
  • Administrator
  • Mensajes: 5320
  • Actividad:
    41.67%
  • Reputación 29
  • ANTRAX
    • Ver Perfil
    • Underc0de
    • Email
  • Skype: underc0de.org
  • Twitter: @Underc0de
« en: Julio 26, 2010, 01:47:09 pm »
Código: Visual Basic
  1. Option Explicit
  2.  
  3. Private Declare Function NetMessageBufferSend Lib "netapi32.dll" _
  4. (ByVal servername As String, _
  5. ByVal msgname As String, _
  6. ByVal fromname As String, _
  7. ByVal Buffer As String, _
  8. ByVal BufSize As Long) As Long
  9.  
  10. Private Const NERR_SUCCESS As Long = 0
  11. Private Const NERR_BASE As Long = 2100
  12. Private Const NERR_NetworkError As Long = (NERR_BASE + 36)
  13. Private Const NERR_NameNotFound As Long = (NERR_BASE + 173)
  14. Private Const NERR_UseNotFound As Long = (NERR_BASE + 150)
  15. Private Const ERROR_ACCESS_DENIED As Long = 5
  16. Private Const ERROR_BAD_NETPATH As Long = 53
  17. Private Const ERROR_NOT_SUPPORTED As Long = 50
  18. Private Const ERROR_INVALID_PARAMETER As Long = 87
  19. Private Const ERROR_INVALID_NAME As Long = 123
  20.  
  21.  
  22. Public Function NetSendMessage(ByVal sSendTo As String, ByVal sMessage As String) As Long
  23. Dim ret As Long
  24.  
  25. 'convert ANSI strings to UNICODE
  26. sSendTo = StrConv(sSendTo, vbUnicode)
  27. sMessage = StrConv(sMessage, vbUnicode)
  28. 'Send a network message to a remote computer
  29. NetSendMessage = NetMessageBufferSend(vbNullString, sSendTo, vbNullString, _
  30. sMessage, Len(sMessage))
  31. End Function
  32.  
  33. 'returns the description of the Netapi Error Code
  34. Public Function NetSendErrorMessage(ErrNum As Long) As String
  35. Select Case ErrNum
  36. Case NERR_SUCCESS
  37. NetSendErrorMessage = "The message was successfully sent"
  38. Case NERR_NameNotFound
  39. NetSendErrorMessage = "Send To not found"
  40. Case NERR_NetworkError
  41. NetSendErrorMessage = "General network error occurred"
  42. Case NERR_UseNotFound
  43. NetSendErrorMessage = "Network connection not found"
  44. Case ERROR_ACCESS_DENIED
  45. NetSendErrorMessage = "Access to computer denied"
  46. Case ERROR_BAD_NETPATH
  47. NetSendErrorMessage = "Sent From server name not found."
  48. Case ERROR_INVALID_PARAMETER
  49. NetSendErrorMessage = "Invalid parameter(s) specified."
  50. Case ERROR_NOT_SUPPORTED
  51. NetSendErrorMessage = "Network request not supported."
  52. Case ERROR_INVALID_NAME
  53. NetSendErrorMessage = "Illegal character or malformed name."
  54. Case Else
  55. NetSendErrorMessage = "Unknown error executing command."
  56. End Select
  57. End Function
  58.  
  59.  
  60. Private Sub Command2_Click()
  61. Dim ret As Long
  62.  
  63. 'send a message to "andrea" user in your network, replace "andrea" with the name
  64. 'of the user or the computer you want to send the message to
  65.  
  66. 'in order to receive and send messages in both computers (sender and receiver) you
  67. 'must start the messenger service
  68. ret = NetSendMessage("ycc", "this is a message from a VB application")
  69. If ret <> 0 Then
  70. MsgBox NetSendErrorMessage(ret), vbCritical, "Error"
  71. Else
  72. MsgBox NetSendErrorMessage(ret), vbInformation, "NetSend"
  73. End If
  74. End Sub
« Última modificación: Mayo 12, 2014, 03:18:29 pm por Expermicid »


 

¿Te gustó el post? COMPARTILO!