CoePSX Posted August 4, 2006 Share Posted August 4, 2006 Hi, i got this C source code that sends Net messages with different names. I had a lot of fun with this in college, and even use it at home to make the names look better. But it has a flaw, it messes all the "non-simple" chars (my english sucks). Ex: a shows a. á shows Ú So... i tried a lot with dllcalls to do this but i couldn't. Could someone please help me send a message like this in AutoIt? This is the original C code. expandcollapse popup/* Fake NetSend for Windows NT/2000/XP v1.01 Written by me (Caio Proiete). mailto:caio@proiete.com.br Copyright (c) 2003. If you find any bugs, please notify me! You may use it, abuse it, redistribute it, in any way you desire, but don't change the author credits;) HISTORY 2003-06-08 - First version. Bugs: Zero, I hope :) 2003-06-11 - Version 1.01. Just improving the code. */ const char szAbout[] = \ "Fake NetSend for Windows NT/2000/XP v1.01\n" \ "by Caio Proiete (caio@proiete.com.br)\n"; const char szUsage[] = \ "Usage: FakeSend [Sender] [Receiver] \"[Message]\"\n" \ "Example: FakeSend James Kevin \"Hi Kevin this is James!\"\n"; const char szMailSlotPath[] = "\\\\%s\\MAILSLOT\\messngr"; const char szMsgFormat[] = "%s\r%s\r%s\r"; const unsigned char nTotalParam = 4; bool NetSend(const char * szSender, const char * szReceiver, const char * szMessage); // Exclude rarelly used Windows stuff #define WIN32_LEAN_AND_MEAN #include <stdio.h> #include <windows.h> int main(int argc, char **argv) { /////////////////////////////////////////// // What do we expect in argv variable? // /////////////////////////////////////////// // argv[0] = Application PathName // // argv[1] = Sender's Name // // argv[2] = Receiver's Login or Machine // // argv[3] = Message // /////////////////////////////////////////// // We have all needed parameters? if (argc == nTotalParam) { // Just showing a status printf("%s\n" \ "Sending Fake Message:\n" \ "Sender...: %s\n" \ "Receiver.: %s\n" \ "Message..: %s\n", szAbout, argv[1], argv[2], argv[3]); if (NetSend(argv[1], argv[2], argv[3])) printf("Message sent!\n"); else printf("Error sending the message!\n"); } else printf("%s\n%s", szAbout, szUsage); // Show About and Usage descriptions return 0; } /* This function takes the Sender's and Receiver's Name, the Message and then send the "Fake" message */ bool NetSend(const char * szSender, const char * szReceiver, const char * szMessage) { // Our main variables char * pszMailSlot = NULL; unsigned char * pucMessage = NULL; unsigned int nMailSlotLen, nMsgFormatLen; HANDLE hHandle; DWORD dwBytesWritten; bool bRet = false; // Get the length of the strings nMailSlotLen = strlen(szReceiver) + sizeof(szMailSlotPath); nMsgFormatLen = strlen(szSender) + strlen(szReceiver) + strlen(szMessage) + sizeof(szMsgFormat); // Allocate necessary memory pszMailSlot = new char[nMailSlotLen]; pucMessage = new unsigned char[nMsgFormatLen]; // Network path for <Receiver> MailSlot: // "\\Receiver\MAILSLOT\messngr" sprintf(pszMailSlot, szMailSlotPath, szReceiver); // Message Format: // "Sender\0Receiver\0Message\0" // sprintf doesn't work with \0 so here I'm using \r sprintf((char *)pucMessage, szMsgFormat, szSender, szReceiver, szMessage); // Replace all '\r' characters with '\0' for (unsigned short i = 0; i < nMsgFormatLen; i++) { if (pucMessage[i] == '\r') pucMessage[i] = '\0'; else if (pucMessage[i] == '\0') break; } // Create the file into Receiver's MailSlot and get a Handle to this file hHandle = CreateFile(pszMailSlot, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); // We have a valid handle? if (hHandle) { // Write the message to file bRet = (WriteFile(hHandle, pucMessage, (DWORD)nMsgFormatLen, &dwBytesWritten, NULL) == TRUE); // Free the handle CloseHandle(hHandle); } return bRet; } Thanks in advance, Coe [quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"]╔══════════════════════════════╗║░░██░░░░░░░░██░░███░░░████░░░█║║░█░░█░░██░░█░░█░█░░█░█░░░░█░█░║║░█░░░░█░░█░████░███░░░██░░░█░░║║░█░░█░█░░█░█░░░░█░░░░░░░█░█░█░║║░░██░░░██░░░██░░█░░░░███░█░░░█║╚══════════════════════════════╝[/font] Link to comment Share on other sites More sharing options...
CoePSX Posted August 10, 2006 Author Share Posted August 10, 2006 I kept working on it, please someone help me. It doesn't work yet. The DLLCalls return OK and the bytes writen return right too, but the message just doens't go. I really need help on it. expandcollapse popup#NoTrayIcon #include <GUIConstants.au3> GUICreate("NetSend", 200, 140, -1, -1) GUICtrlCreateLabel("Message:", 10, 13, 50, 15) $Message = GUICtrlCreateInput("", 60, 10, 130, 20) GUICtrlCreateLabel("Sender:", 10, 43, 50, 15) $Sender = GUICtrlCreateInput("", 60, 40, 130, 20) GUICtrlCreateLabel("Receiver:", 10, 73, 50, 15) $Receiver = GUICtrlCreateInput("", 60, 70, 130, 20) $OK = GUICtrlCreateButton("Send", 10, 100, 180, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $OK $Send = NetSend(GUICtrlRead($Sender), GUICtrlRead($Receiver), GUICtrlRead($Message)) If $Send = 0 Then MsgBox(16, "NetSend", "Error! The message could not be sent") EndIf EndSwitch WEnd Func NetSend($szSender, $szReceiver, $szMessage) Local Const $GENERIC_WRITE = 0x40000000 Local Const $FILE_SHARE_READ = 0x00000001 Local Const $OPEN_EXISTING = 0x00000003 Local Const $FILE_ATTRIBUTE_NORMAL = 0x00000080 Local Const $szMailSlotPath = "\\\\%s\\MAILSLOT\\messngr" Local Const $szMsgFormat = "%s\r%s\r%s\r" Local $dwBytesWritten Local $bRet = 0 Local $nMsgFormatLen = StringLen(StringFormat($szMsgFormat, $szSender, $szReceiver, $szMessage)) Local $pucMessage = DllStructCreate("char[" & $nMsgFormatLen & "]") DllStructSetData($pucMessage, 1, StringFormat($szMsgFormat, $szSender, $szReceiver, $szMessage)) Local $nMailSlotLen = StringLen(StringFormat($szMailSlotPath, $szReceiver)) + 1 Local $pszMailSlot = DllStructCreate("char[" & $nMailSlotLen & "]") DllStructSetData($pszMailSlot, 1, StringFormat($szMailSlotPath, $szReceiver)) Local $hHandle = DllCall("kernel32.dll", "hwnd", "CreateFile", "ptr", DllStructGetPtr($pszMailSlot), _ "int", $GENERIC_WRITE, _ "int", $FILE_SHARE_READ, _ "ptr", 0, _ "int", $OPEN_EXISTING, _ "int", $FILE_ATTRIBUTE_NORMAL, _ "int", 0) $hHandle = $hHandle[0] If $hHandle Then Local $bRet = DllCall("kernel32.dll", "int", "WriteFile", "hwnd", $hHandle, _ "ptr", DllStructGetPtr($pucMessage), _ "int", $nMsgFormatLen, _ "long_ptr", $dwBytesWritten, _ "ptr", 0) $bRet = $bRet[4] DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hHandle) EndIf Return $bRet EndFunc [quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"]╔══════════════════════════════╗║░░██░░░░░░░░██░░███░░░████░░░█║║░█░░█░░██░░█░░█░█░░█░█░░░░█░█░║║░█░░░░█░░█░████░███░░░██░░░█░░║║░█░░█░█░░█░█░░░░█░░░░░░░█░█░█░║║░░██░░░██░░░██░░█░░░░███░█░░░█║╚══════════════════════════════╝[/font] Link to comment Share on other sites More sharing options...
CoePSX Posted August 11, 2006 Author Share Posted August 11, 2006 I did it! I sent the message! Although... it still messes those characters like á, À, Ü etc... It's a net send function purely on autoit, based on DllCalls. I hope this is useful for someone... I'll post it on Scripts and Scraps. expandcollapse popup#NoTrayIcon #include <GUIConstants.au3> GUICreate("NetSend", 200, 140, -1, -1) GUICtrlCreateLabel("Message:", 10, 13, 50, 15) $Message = GUICtrlCreateInput("", 60, 10, 130, 20) GUICtrlCreateLabel("Sender:", 10, 43, 50, 15) $Sender = GUICtrlCreateInput("", 60, 40, 130, 20) GUICtrlCreateLabel("Receiver:", 10, 73, 50, 15) $Receiver = GUICtrlCreateInput("", 60, 70, 130, 20) $OK = GUICtrlCreateButton("Send", 10, 100, 180, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $OK $Send = NetSend(GUICtrlRead($Sender), GUICtrlRead($Receiver), GUICtrlRead($Message)) If $Send = 0 Then MsgBox(16, "NetSend", "Error! The message could not be sent!") EndIf EndSwitch WEnd Func NetSend($szSender, $szReceiver, $szMessage) Local Const $GENERIC_WRITE = 0x40000000 Local Const $FILE_SHARE_READ = 0x00000001 Local Const $OPEN_EXISTING = 0x00000003 Local Const $FILE_ATTRIBUTE_NORMAL = 0x00000080 Local $bRet = 0 Local $pucMessage = DllStructCreate("byte[" & StringLen($szSender & Chr(0) & $szReceiver & Chr(0) & $szMessage & Chr(0)) & "]") For $i = 1 To StringLen($szSender & Chr(0) & $szReceiver & Chr(0) & $szMessage & Chr(0)) DllStructSetData($pucMessage, 1, Asc(StringMid($szSender & Chr(0) & $szReceiver & Chr(0) & $szMessage & Chr(0), $i, 1)), $i) Next Local $pszMailSlot = DllStructCreate("char[" & StringLen("\\" & $szReceiver & "\MAILSLOT\messngr") + 1 & "]") DllStructSetData($pszMailSlot, 1, "\\" & $szReceiver & "\MAILSLOT\messngr") Local $hHandle = DllCall("kernel32.dll", "hwnd", "CreateFile", "ptr", DllStructGetPtr($pszMailSlot), _ "int", $GENERIC_WRITE, _ "int", $FILE_SHARE_READ, _ "ptr", 0, _ "int", $OPEN_EXISTING, _ "int", $FILE_ATTRIBUTE_NORMAL, _ "int", 0) $hHandle = $hHandle[0] If $hHandle Then Local $bRet = DllCall("kernel32.dll", "int", "WriteFile", "hwnd", $hHandle, _ "ptr", DllStructGetPtr($pucMessage), _ "int", StringLen($szSender & Chr(0) & $szReceiver & Chr(0) & $szMessage & Chr(0)), _ "long_ptr", 0, _ "ptr", 0) $bRet = $bRet[4] DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hHandle) EndIf Return $bRet EndFuncNetSend.au3 [quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"]╔══════════════════════════════╗║░░██░░░░░░░░██░░███░░░████░░░█║║░█░░█░░██░░█░░█░█░░█░█░░░░█░█░║║░█░░░░█░░█░████░███░░░██░░░█░░║║░█░░█░█░░█░█░░░░█░░░░░░░█░█░█░║║░░██░░░██░░░██░░█░░░░███░█░░░█║╚══════════════════════════════╝[/font] Link to comment Share on other sites More sharing options...
Ontosy Posted December 24, 2007 Share Posted December 24, 2007 It is possibile to add send via "Ip Address" and not only Computer name? Link to comment Share on other sites More sharing options...
bwtbyca Posted December 24, 2007 Share Posted December 24, 2007 I did it! I sent the message! Although... it still messes those characters like á, À, Ü etc... It's a net send function purely on autoit, based on DllCalls. I hope this is useful for someone... I'll post it on Scripts and Scraps. expandcollapse popup#NoTrayIcon #include <GUIConstants.au3> GUICreate("NetSend", 200, 140, -1, -1) GUICtrlCreateLabel("Message:", 10, 13, 50, 15) $Message = GUICtrlCreateInput("", 60, 10, 130, 20) GUICtrlCreateLabel("Sender:", 10, 43, 50, 15) $Sender = GUICtrlCreateInput("", 60, 40, 130, 20) GUICtrlCreateLabel("Receiver:", 10, 73, 50, 15) $Receiver = GUICtrlCreateInput("", 60, 70, 130, 20) $OK = GUICtrlCreateButton("Send", 10, 100, 180, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $OK $Send = NetSend(GUICtrlRead($Sender), GUICtrlRead($Receiver), GUICtrlRead($Message)) If $Send = 0 Then MsgBox(16, "NetSend", "Error! The message could not be sent!") EndIf EndSwitch WEnd Func NetSend($szSender, $szReceiver, $szMessage) Local Const $GENERIC_WRITE = 0x40000000 Local Const $FILE_SHARE_READ = 0x00000001 Local Const $OPEN_EXISTING = 0x00000003 Local Const $FILE_ATTRIBUTE_NORMAL = 0x00000080 Local $bRet = 0 Local $pucMessage = DllStructCreate("byte[" & StringLen($szSender & Chr(0) & $szReceiver & Chr(0) & $szMessage & Chr(0)) & "]") For $i = 1 To StringLen($szSender & Chr(0) & $szReceiver & Chr(0) & $szMessage & Chr(0)) DllStructSetData($pucMessage, 1, Asc(StringMid($szSender & Chr(0) & $szReceiver & Chr(0) & $szMessage & Chr(0), $i, 1)), $i) Next Local $pszMailSlot = DllStructCreate("char[" & StringLen("\\" & $szReceiver & "\MAILSLOT\messngr") + 1 & "]") DllStructSetData($pszMailSlot, 1, "\\" & $szReceiver & "\MAILSLOT\messngr") Local $hHandle = DllCall("kernel32.dll", "hwnd", "CreateFile", "ptr", DllStructGetPtr($pszMailSlot), _ "int", $GENERIC_WRITE, _ "int", $FILE_SHARE_READ, _ "ptr", 0, _ "int", $OPEN_EXISTING, _ "int", $FILE_ATTRIBUTE_NORMAL, _ "int", 0) $hHandle = $hHandle[0] If $hHandle Then Local $bRet = DllCall("kernel32.dll", "int", "WriteFile", "hwnd", $hHandle, _ "ptr", DllStructGetPtr($pucMessage), _ "int", StringLen($szSender & Chr(0) & $szReceiver & Chr(0) & $szMessage & Chr(0)), _ "long_ptr", 0, _ "ptr", 0) $bRet = $bRet[4] DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hHandle) EndIf Return $bRet EndFunc Link to comment Share on other sites More sharing options...
bwtbyca Posted December 24, 2007 Share Posted December 24, 2007 The Ip address is the true address of the Computer. The name Resolution is done through a DNS server. In short yes , substitute the ip for the name characters. Link to comment Share on other sites More sharing options...
Ontosy Posted December 24, 2007 Share Posted December 24, 2007 Do you have tryed. The Ip Addres Net Send is not working in my lan. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now