我调用了net send实现信使功能,但是我想知道怎样能让我这边得到反馈,即利用netapi32.dll来实现在向我发送回馈消息。告知我目标机已经收到信使消息~或者还有什么除了利用那个dll之外别的方法?

解决方案 »

  1.   

    from 超级猛料function NetSend(dest, Source, Msg: string): Longint; overload; 
    type 
      TNetMessageBufferSendFunction = function(servername, msgname, fromname: PWideChar; 
        buf: PWideChar; buflen: Cardinal): Longint;  
      stdcall; 
    var 
      NetMessageBufferSend: TNetMessageBufferSendFunction; 
      SourceWideChar: PWideChar; 
      DestWideChar: PWideChar; 
      MessagetextWideChar: PWideChar; 
      Handle: THandle; 
    begin 
      Handle := LoadLibrary('NETAPI32.DLL'); 
      if Handle = 0 then 
      begin 
        Result := GetLastError; 
        Exit; 
      end; 
        @NetMessageBufferSend := GetProcAddress(Handle, 'NetMessageBufferSend'); 
      if @NetMessageBufferSend = nil then 
      begin 
        Result := GetLastError; 
        Exit; 
      end;   MessagetextWideChar := nil; 
      SourceWideChar      := nil; 
      DestWideChar        := nil;   try 
        GetMem(MessagetextWideChar, Length(Msg) * SizeOf(WideChar) + 1); 
        GetMem(DestWideChar, 20 * SizeOf(WideChar) + 1); 
        StringToWideChar(Msg, MessagetextWideChar, Length(Msg) * SizeOf(WideChar) + 1); 
        StringToWideChar(Dest, DestWideChar, 20 * SizeOf(WideChar) + 1);     if Source = '' then 
          Result := NetMessageBufferSend(nil, DestWideChar, nil, 
            MessagetextWideChar, Length(Msg) * SizeOf(WideChar) + 1) 
        else 
        begin 
          GetMem(SourceWideChar, 20 * SizeOf(WideChar) + 1); 
          StringToWideChar(Source, SourceWideChar, 20 * SizeOf(WideChar) + 1); 
          Result := NetMessageBufferSend(nil, DestWideChar, SourceWideChar, 
            MessagetextWideChar, Length(Msg) * SizeOf(WideChar) + 1); 
          FreeMem(SourceWideChar); 
        end; 
      finally 
        FreeMem(MessagetextWideChar); 
        FreeLibrary(Handle); 
      end; 
    end; function NetSend(Dest, Msg: string): Longint; overload; 
    begin 
      Result := NetSend(Dest, '', Msg); 
    end; function NetSend(Msg: string): Longint; overload; 
    begin 
      Result := NetSend('', '', Msg); 
    end; // Example: procedure TForm1.Button1Click(Sender: TObject); 
    const 
      NERR_BASE = 2100; 
      NERR_NameNotFound = NERR_BASE + 173; 
      NERR_NetworkError = NERR_BASE + 36; 
      NERR_Success = 0; 
    var 
      Res: Longint; 
      sMsg: string; 
    begin 
      Res := NetSend('LoginName', 'Your Message...'); 
      case Res of 
       /////也许这里是你要的东西;
        ERROR_ACCESS_DENIED: sMsg := 'user does not have access to the requested information.'; 
        ERROR_INVALID_PARAMETER: sMsg := 'The specified parameter is invalid.'; 
        ERROR_NOT_SUPPORTED: sMsg := 'This network request is not supported.'; 
        NERR_NameNotFound: sMsg := 'The user name could not be found.'; 
        NERR_NetworkError: sMsg := 'A general failure occurred in the network hardware.'; 
        NERR_Success: sMsg := 'Message sent!'; 
      end; 
      ShowMessage(sMsg); 
    end; 
      

  2.   

    同意outer2000(天外流星) 的
      

  3.   

    ShellExecute(handle,'open','net.exe',pchar(' send 192.0.0.210 abcde'),'',SW_hide)ShellExecute 有一个返回值你看看对你有没有用。Value Meaning
    0 The operating system is out of memory or resources.
    ERROR_FILE_NOT_FOUND The specified file was not found.
    ERROR_PATH_NOT_FOUND The specified path was not found.
    ERROR_BAD_FORMAT The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).
    SE_ERR_ACCESSDENIED The operating system denied access to the specified file. 
    SE_ERR_ASSOCINCOMPLETE The filename association is incomplete or invalid.
    SE_ERR_DDEBUSY The DDE transaction could not be completed because other DDE transactions were being processed.
    SE_ERR_DDEFAIL The DDE transaction failed.
    SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the request timed out.
    SE_ERR_DLLNOTFOUND The specified dynamic-link library was not found. 
    SE_ERR_FNF The specified file was not found. 
    SE_ERR_NOASSOC There is no application associated with the given filename extension.
    SE_ERR_OOM There was not enough memory to complete the operation.
    SE_ERR_PNF The specified path was not found.
    SE_ERR_SHARE A sharing violation occurred.
      

  4.   

    试试这个超时。(返回值)
    可能就是发不通吧。SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the request timed out.
      

  5.   

    我这另外有个delphi的代码,晚上发给你看看
      

  6.   

    呵呵
    信使服务(messager)调用的函数是NetMessageBufferSend
    ERROR_ACCESS_DENIED   The user does not have access to the requested information. 
    ERROR_INVALID_PARAMETER    The specified parameter is invalid. 
    ERROR_NOT_SUPPORTED    This network request is not supported. 
    NERR_NameNotFound    The user name could not be found. 
    NERR_NetworkError    A general failure occurred in the network hardware. 上面就是它的返回值,如果手边有msdn,里面有更详细的说明
      

  7.   

    unit UMesApi;
    interface
    uses SysUtils, Classes;function ToUnicode(str:string;dest:PWideChar):integer;
    function SendMsg(Toh,From,Msg:string):integer;
    function NetMessageBufferSend(servername:PWideChar;
                                  MsgName:PWideChar;
                                  FromName:PWideChar;
                                  Buf: PWideChar;
                                  var BufLen:integer):integer;cdecl;
    implementation
    function ToUnicode(str:string;dest:PWideChar):integer;
    var
      len:integer;
    begin
      len:=Length(str)*2;
        //len:=length(dest^);
      StringToWideChar(str,dest,len);
      Result:=len;
    end;
    function NetMessageBufferSend; external 'netapi32.dll' name 'NetMessageBufferSend';function SendMsg(Toh,From,Msg:string):integer;
    var
      ToName :array [0..64] of WideChar;
      WMsgText:array [0..1000] of WideChar;
      MsgLen,i:integer;
    begin
      for i := 0 to 64 do ToName[i] := #0;
      ToUnicode(Toh,ToName);
      for i := 0 to 1000 do WMsgText[i] := #0;  MsgLen:=ToUnicode(Msg,WMsgText);
      Result:=NetMessageBufferSend(nil,ToName,nil,@WMsgText,MsgLen);end;end.SendMsg得到返回值。
    你判断一下返回值就行了。
      

  8.   

    信使服务(messager)调用的函数是NetMessageBufferSend
    可以根据他的返回值来判断,返回0表示成功
    别的几样都是失败
    具体代码我也有的,要的话可以给我发消息