我将所有代码放出来了!大家看看吧!为什么我总是不行!<br><br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, TFlatSpeedButtonUnit, Buttons;<br><br>type<br> TForm1 = class(TForm)<br> ComboBox1: TComboBox;<br> ComboBox2: TComboBox;<br> GroupBox1: TGroupBox;<br> RadioButton1: TRadioButton;<br> RadioButton2: TRadioButton;<br> Label1: TLabel;<br> SpeedButton1: TSpeedButton;<br> procedure RadioButton1Click(Sender: TObject);<br> procedure RadioButton2Click(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> procedure SpeedButton1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br><br><br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br> implementation<br>function<br>NetMessageBufferSend(servername
WideChar;msgname
WideChar;<br>fromname
WideChar;buf
WideChar;buflen
WORD)
WORD;stdcall;external 'netapi32.dll'<br><br>{$R *.dfm}<br>type<br> TNetResourceArray = ^TNetResource; //网络资源类型的数组<br>Function GetServerList( var List : TStringList ) : Boolean;<br><br>Var<br>NetResource : TNetResource;<br>Buf : Pointer;<br>Count,BufSize,Res : DWORD;<br>lphEnum : THandle;<br>p:TNetResourceArray;<br>i,j : SmallInt;<br>NetworkTypeList : TList;<br>Begin<br>Result := False;<br>NetworkTypeList := TList.Create;<br>List.Clear;<br>Res := WNetOpenEnum( RESOURCE_GLOBALNET, RESOURCETYPE_DISK,<br>RESOURCEUSAGE_CONTAINER, Nil,lphEnum);<br>//获取整个网络中的文件资源的句柄,lphEnum为返回名柄<br>If Res <> NO_ERROR Then exit;<br>//执行失败,退出<br><br>//执行成功,开始获取整个网络中的网络类型信息<br>Count := $FFFFFFFF;<br>//不限资源数目<br>BufSize := 8192;<br>//缓冲区大小设置为8K<br>GetMem(Buf, BufSize);<br>//申请内存,用于获取工作组信息<br>Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);<br>If ( Res = ERROR_NO_MORE_ITEMS )<br>//资源列举完毕<br>or (Res <> NO_ERROR )<br>//执行失败<br>Then Exit;<br><br>P := TNetResourceArray(Buf);<br>For I := 0 To Count - 1 Do<br>//记录各个网络类型的信息<br>Begin<br>NetworkTypeList.Add(p);<br>Inc(P);<br>End;<br><br>//WNetCloseEnum关闭一个列举句柄<br>Res:= WNetCloseEnum(lphEnum);<br>//关闭一次列举<br>If Res <> NO_ERROR Then exit;<br>For J := 0 To NetworkTypeList.Count-1 Do<br>//列出各个网络类型中的所有工作组名称<br>Begin<br>//列出一个网络类型中的所有工作组名称<br>NetResource := TNetResource(NetworkTypeList.Items[J]^);<br>//网络类型信息<br>//获取某个网络类型的文件资源的句柄,NetResource为网络类型信息,lphEnum为返回名柄<br>Res := WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK,<br>RESOURCEUSAGE_CONTAINER, @NetResource,lphEnum);<br>If Res <> NO_ERROR Then break;<br>//执行失败<br>While true Do<br>//列举一个网络类型的所有工作组的信息<br>Begin<br>Count := $FFFFFFFF;<br>//不限资源数目<br>BufSize := 8192;<br>//缓冲区大小设置为8K<br>GetMem(Buf, BufSize);<br>//申请内存,用于获取工作组信息,获取一个网络类型的文件资源信息,<br>Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);<br>If ( Res = ERROR_NO_MORE_ITEMS )<br>//资源列举完毕<br>or (Res <> NO_ERROR)<br>//执行失败<br>then break;<br>P := TNetResourceArray(Buf);<br>For I := 0 To Count - 1 Do<br>//列举各个工作组的信息<br>Begin<br>List.Add( StrPAS( P^.lpRemoteName ));<br>//取得一个工作组的名称<br>Inc(P);<br>End;<br>End;<br>Res := WNetCloseEnum(lphEnum);<br>//关闭一次列举<br>If Res <> NO_ERROR Then break;<br>//执行失败<br>End;<br>Result := True;<br>FreeMem(Buf);<br>NetworkTypeList.Destroy;<br>End;<br>Function GetUsers(GroupName:string;var List:TStringList):Boolean;<br>Var<br> NetResource:TNetResource;<br> Buf : Pointer;<br> Count,BufSize,Res : DWord;<br> Ind : Integer;<br> lphEnum : THandle;<br> Temp:TNetResourceArray;<br>Begin<br> Result := False;<br> List.Clear;<br> FillChar(NetResource, SizeOf(NetResource), 0); //初始化网络层次信息<br> NetResource.lpRemoteName := @GroupName[1]; //指定工作组名称<br> NetResource.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;//类型为服务器(工作组)<br> NetResource.dwUsage := RESOURCEUSAGE_CONTAINER;<br> NetResource.dwScope := RESOURCETYPE_DISK; //列举文件资源信息<br> Res := WNetOpenEnum( RESOURCE_GLOBALNET, RESOURCETYPE_DISK,RESOURCEUSAGE_CONTAINER, @NetResource,lphEnum);<br>If Res <> NO_ERROR Then Exit; //执行失败<br>While True Do //列举指定工作组的网络资源<br> Begin<br> Count := $FFFFFFFF; //不限资源数目<br> BufSize := 8192; //缓冲区大小设置为8K<br> GetMem(Buf, BufSize);//申请内存,用于获取工作组信息,获取计算机名称<br> Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);<br> If Res = ERROR_NO_MORE_ITEMS Then break;//资源列举完毕<br> If (Res <> NO_ERROR) then Exit;//执行失败<br> Temp := TNetResourceArray(Buf);<br> For Ind := 0 to Count - 1 do//列举工作组的计算机名称<br> Begin<br> List.Add(Temp^.lpRemoteName);<br> Inc(Temp);<br> End;<br>End;<br>Res := WNetCloseEnum(lphEnum);//关闭一次列举<br>If Res <> NO_ERROR Then exit;//执行失败<br> Result:=True;<br> FreeMem(Buf);<br>end;<br>procedure TForm1.RadioButton1Click(Sender: TObject);<br>begin<br>combobox1.Visible :=true;<br>end;<br><br>procedure TForm1.RadioButton2Click(Sender: TObject);<br>begin<br>combobox1.Visible :=false;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br> ZAppName: array[0..127] of char;<br> Hold: String;<br> Found: HWND;<br>begin //防止程序多次运行<br> Hold := Application.Title;<br> Application.Title := 'OnlyOne'<br> + IntToStr(HInstance); // 暂时修改窗口标题<br> StrPCopy(ZAppName, Hold); // 原窗口标题<br> Found := FindWindow(nil, ZAppName); // 查找窗口<br> Application.Title := Hold; // 恢复窗口标题<br> if Found<>0 then begin<br> // 若找到则激活已运行的程序并结束自身<br><br> ShowWindow(Found, SW_RESTORE);<br> Application.Terminate;<br> end;<br><br><br>end;<br><br>procedure TForm1.SpeedButton1Click(Sender: TObject);<br>var<br> com1,com2:WideString;<br> a:string;<br> GroupList:TStringList;<br>ComputerList:TStringList;<br>i,j:integer;<br>begin<br>GroupList:=TStringList.Create;<br>if not GetServerList(GroupList) then //取得网络内所有工作组<br>begin<br>GroupList.Free;<br>Exit;<br>end;<br>ComputerList:=TStringList.Create;<br>for i:=0 to GroupList.Count-1 do//枚举没个工作组的计算机<br>begin<br>ComputerList.Clear;<br>if GetUsers(GroupList.Strings
,ComputerList) then<br> for j:=0 to ComputerList.Count-1 do<br> ComboBox1.Items.Add(ComputerList.Strings[j]);<br>end;<br>if ComboBox1.Items.Count>0 then ComboBox1.ItemIndex:=0;<br>GroupList.Free;<br>ComputerList.Free;<br>if RadioButton2.Checked =true then<br>begin<br> a:='command.com /c net send * '+combobox2.Text; //net send 命令<br> WinExec(PChar(a), SW_SHOWNORMAL);<br> ShowMessage('所有信息已经发送完毕!')<br>end<br>else<br> com2:=combobox2.Text ;<br> com1:=combobox1.Text ;<br> NetMessageBufferSend(NIL,PWidechar(com1),Nil,PWideChar(com2),Length(String(com2)));<br> ShowMessage('发往' + combobox1.Text + '的信息已经发出了')<br><br>end;<br><br>end.<br><br><br>