Autor Beitrag
Stianbl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29



BeitragVerfasst: So 10.10.04 11:55 
Hi again! :D
I`m back to delphi programming, and now I need a way to send Net Send messages in XP...
I want it to send a netsend message to a username (edit1.text) with the message (edit2.text)!
I don`t want to use more that this one .exe file...

Thanks in advanse! :wink:
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: So 10.10.04 12:12 
Stianbl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29



BeitragVerfasst: So 10.10.04 12:20 
Thanks m8! :P
Gast
Gast
Erhaltene Danke: 1



BeitragVerfasst: So 10.10.04 14:01 
The job can also be done from Win9x - which is not possible using the above mentioned function (which is only available on the NT platform).

Check this out: assarbad.net/stuff/!...endusingmailslot.txt

The function is ANSI only, currently.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
(******************************************************************************
 This code is PUBLIC DOMAIN!
 ******************************************************************************)


function NetMessageBufferSendSubstA(ServerName, MsgName, FromName, Msg: AnsiString): Boolean;
{.$DEFINE SYNCHRONOUS}
const
  szService = '\mailslot\messngr';
  MaxBufLen = $700;
var
  hFile: THandle;
  WrittenBytes: DWORD;
{$IFNDEF SYNCHRONOUS}
  ovs: OVERLAPPED;
  EventName:String;
{$ENDIF}
begin
  Result := False;
  if Length(Msg) > MaxBufLen then
    SetLength(Msg, MaxBufLen);
{$IFNDEF SYNCHRONOUS}
  EventName:='NetSendEvent_'+ServerName;
{$ENDIF}
  ServerName := '\\' + Servername + szService;
  hFile := CreateFileA(
    @ServerName[1], GENERIC_WRITE, FILE_SHARE_READ, nil, OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL or FILE_FLAG_NO_BUFFERING or FILE_FLAG_OVERLAPPED, 0);
  if hFile <> INVALID_HANDLE_VALUE then
  try
    Msg := FromName + #0 + MsgName + #0 + Msg;
{$IFNDEF SYNCHRONOUS}
    ovs.hEvent := CreateEventA(nil, True, False, @EventName[1]);
    WriteFile(hFile, Pointer(Msg)^, Length(Msg), WrittenBytes, @ovs);
{$ELSE}
    WriteFile(hFile, Pointer(Msg)^, Length(Msg), WrittenBytes, nil);
{$ENDIF}
    Result := GetLastError = ERROR_IO_PENDING;
  finally
{$IFNDEF SYNCHRONOUS}
    if WaitForSingleObject(ovs.hEvent, INFINITE) <> WAIT_TIMEOUT then
{$ENDIF}
      CloseHandle(hFile);
  end;
end;


Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
Stianbl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29



BeitragVerfasst: So 10.10.04 20:07 
Thank you very much!
One more question:

Is it possible to make the code a bit smaller?
I mean, like use a shallexecute() command or something?
I don`t need the net send function to see if there are any errors while sending, or if the message was recieved, just a simple code that works...

Thanks in advance! 8)
Gast
Gast
Erhaltene Danke: 1



BeitragVerfasst: So 10.10.04 20:25 
Just copy the code into your project and call the function

ausblenden Delphi-Quelltext
1:
NetMessageBufferSendSubstA(ServerName, MsgName, FromName, Msg);					


The result is a Boolean. Nothing simpler than this. If you use NetMessageBufferSend() you need to convert some arguments from String to PChar and the like. No need for this here.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 10.10.04 20:28 
Why would you do this that complicated that complicated???

Try this:
www.swissdelphicente.../showcode.php?id=617

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Gast
Gast
Erhaltene Danke: 1



BeitragVerfasst: So 10.10.04 20:39 
BenBE hat folgendes geschrieben:
Why would you do this that complicated that complicated???
Compatibility?!

BenBE hat folgendes geschrieben:
Try this:
www.swissdelphicente.../showcode.php?id=617
Is this less complicated? *g*
First you also need to copy the code if you don't want to deal with it's internals and furthermore it's only compatible with Windows NT/2K/XP. My code is compatible with Win 9x as well.

There's even an advantage for NT platform: the Messenger service does not have to be started for my code to work.


Zuletzt bearbeitet von Gast am So 10.10.04 22:48, insgesamt 1-mal bearbeitet
Stianbl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29



BeitragVerfasst: So 10.10.04 21:20 
Assarbad: I really can`t get this code to work.. :? I copy/paste it into delphi 6, and made a button and three editboxes...

Then on the button I inserted this code:

NetMessageBufferSendSubstA(Edit1.text, Edit2.text, Edit3.text, Msg);

Yeah, I know.. I`m a noob, so sorry if this is a really simple question.. :cry:

One little question:
Is it possible to read and write some text inside a .dll, .exe, .bat, .txt file in delphi?
Like let delphi write "hello everybody" on the second line, and read a password at line 4, letter 8-14.. ?!?! :roll:

This is what I`v made so far in delphi 6:
Easy Net Send - A net send program, that executes .bat files and then send messages.
Pizza Timer - LoL.. Just a test I made, but I made it better, and use in on lasn and stuff..
Admin Tools - Uses Client/Server socket to controll other computers! Yeah! 8)
Paralellport Controller - A program I made to my home made computer card that controlls all the fans and lights in my computer...

Thanks in advance!
Gast
Gast
Erhaltene Danke: 1



BeitragVerfasst: So 10.10.04 22:47 
Stianbl hat folgendes geschrieben:
Assarbad: I really can`t get this code to work.. :? I copy/paste it into delphi 6, and made a button and three editboxes...

Then on the button I inserted this code:

NetMessageBufferSendSubstA(Edit1.text, Edit2.text, Edit3.text, Msg);
Edit1.text is the server name without leading backslashes? If so, then tell me wether a simple NET SEND works from the source to the target machine - if this fails my code will also fail.

Stianbl hat folgendes geschrieben:
One little question:
Is it possible to read and write some text inside a .dll, .exe, .bat, .txt file in delphi?
Like let delphi write "hello everybody" on the second line, and read a password at line 4, letter 8-14.. ?!?! :roll:
Please create another thread on this topic. Also: how'd you distinguish a "line" in a binary file? It's impossible. Just tell what you want to do exactly.
Stianbl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29



BeitragVerfasst: Di 12.10.04 16:04 
Ok, I will tell you when I need it! ;)
And I`ll thest the code again..

Thx guys! :P
Gast
Gast
Erhaltene Danke: 1



BeitragVerfasst: Di 12.10.04 16:23 
Good luck!