如何用api获取局域网同一工作组内所有机器名?(20分)

  • 主题发起人 主题发起人 Carem
  • 开始时间 开始时间
http://www.tommstudio.com/newclub30/d_viewdownload.asp?type=bianchengjiqiao&id=7128
 
该页无法显示 <br>您要查看的页当前不可用。网站可能遇到技术问题,或者您需要调整浏览器设置。 <br>
 
还有这里<br>http://www.tommstudio.com/newclub30/d_viewdownload.asp?type=bianchengjiqiao&amp;id=7010
 
我自己写的一个函数:<br>Function NetGetUsers(GroupName: string; var List: TListBox): Boolean;<br>type<br>&nbsp; TNetResourceArray = ^TNetResource;//网络类型的数组<br>Var<br>&nbsp; i: Integer;<br>&nbsp; Buf: Pointer;<br>&nbsp; Temp: TNetResourceArray;<br>&nbsp; lphEnum: THandle;<br>&nbsp; NetResource: TNetResource;<br>&nbsp; Count,BufSize,Res: DWord;<br>begin<br>&nbsp; Result := False;<br>&nbsp; List.Clear;<br>&nbsp; FillChar(NetResource, SizeOf(NetResource), 0);//初始化网络层次信息<br>&nbsp; NetResource.lpRemoteName := @GroupName[1];//指定工作组名称<br>&nbsp; NetResource.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;//类型为服务器(工作组)<br>&nbsp; NetResource.dwUsage := RESOURCEUSAGE_CONTAINER;<br>&nbsp; NetResource.dwScope := RESOURCETYPE_DISK;//列举文件资源信息<br>&nbsp; //获取指定工作组的网络资源句柄<br>&nbsp; Res := WNetOpenEnum( RESOURCE_GLOBALNET, RESOURCETYPE_DISK,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCEUSAGE_CONTAINER, @NetResource,lphEnum);<br>&nbsp; if Res &lt;&gt; NO_ERROR then Exit; //执行失败<br>&nbsp; while True do//列举指定工作组的网络资源<br>&nbsp; begin<br>&nbsp; &nbsp; Count := $FFFFFFFF;//不限资源数目<br>&nbsp; &nbsp; BufSize := 8192;//缓冲区大小设置为8K<br>&nbsp; &nbsp; GetMem(Buf, BufSize);//申请内存,用于获取工作组信息<br>&nbsp; &nbsp; //获取计算机名称<br>&nbsp; &nbsp; Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);<br>&nbsp; &nbsp; if Res = ERROR_NO_MORE_ITEMS then break;//资源列举完毕<br>&nbsp; &nbsp; if (Res &lt;&gt; NO_ERROR) then Exit;//执行失败<br>&nbsp; &nbsp; Temp := TNetResourceArray(Buf);<br>&nbsp; &nbsp; for i := 0 to Count - 1 do//列举工作组的计算机名称<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; //获取工作组的计算机名称,+2表示删除"//",如//wangfajun=&gt;wangfajun<br>&nbsp; &nbsp; &nbsp; List.Items.Add(Temp^.lpRemoteName + 2);<br>&nbsp; &nbsp; &nbsp; inc(Temp);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; Res := WNetCloseEnum(lphEnum);//关闭一次列举<br>&nbsp; if Res &lt;&gt; NO_ERROR then exit;//执行失败<br>&nbsp; Result := True;<br>&nbsp; FreeMem(Buf);<br>end;
 
我是初学者,请问如何用delphi_Dcs,的函数将工作组内的计算名加到combobox里面?
 
List.Items.Add(Temp^.lpRemoteName + 2);<br>把这句的list改成你的combobox名字,就算是初学,也因该学会看书吧?
 
Temp^. &nbsp;出错,为何说temp是未声明的标示符?
 
form1.combobox1.Items.Add(Temp^.lpRemoteName + 2);<br><br>这样增加之后就可以编译,但是combobox1里面没有东西阿!怎么解决〉?<br><br>谢谢!!
 
先这样combobox1.Items.clear,<br>然后调用函数时改变一下你要的参数
 
把var List: TListBox &nbsp;改成 &nbsp;Var List:TComboBox啊,试试吧
 
Function NetGetUsers(GroupName: string; var List: Tcombobox): Boolean;<br>type<br>&nbsp;TNetResourceArray = ^TNetResource;//网络类型的数组<br>Var<br>&nbsp;i: Integer;<br>&nbsp;Buf: Pointer;<br>&nbsp;Temp: TNetResourceArray;<br>&nbsp;lphEnum: THandle;<br>&nbsp;NetResource: TNetResource;<br>&nbsp;Count,BufSize,Res: DWord;<br>begin<br>&nbsp;Result := False;<br>&nbsp;form1.combobox1.Items.clear;<br>&nbsp;FillChar(NetResource, SizeOf(NetResource), 0);//初始化网络层次信息<br>&nbsp;NetResource.lpRemoteName := @GroupName[1];//指定工作组名称<br>&nbsp;NetResource.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;//类型为服务器(工作组)<br>&nbsp;NetResource.dwUsage := RESOURCEUSAGE_CONTAINER;<br>&nbsp;NetResource.dwScope := RESOURCETYPE_DISK;//列举文件资源信息<br>&nbsp;//获取指定工作组的网络资源句柄<br>&nbsp;Res := WNetOpenEnum( RESOURCE_GLOBALNET, RESOURCETYPE_DISK,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RESOURCEUSAGE_CONTAINER, @NetResource,lphEnum);<br>&nbsp;if Res &lt;&gt; NO_ERROR then Exit; //执行失败<br>&nbsp;while True do//列举指定工作组的网络资源<br>&nbsp;begin<br>&nbsp; &nbsp;Count := $FFFFFFFF;//不限资源数目<br>&nbsp; &nbsp;BufSize := 8192;//缓冲区大小设置为8K<br>&nbsp; &nbsp;GetMem(Buf, BufSize);//申请内存,用于获取工作组信息<br>&nbsp; &nbsp;//获取计算机名称<br>&nbsp; &nbsp;Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);<br>&nbsp; &nbsp;if Res = ERROR_NO_MORE_ITEMS then break;//资源列举完毕<br>&nbsp; &nbsp;if (Res &lt;&gt; NO_ERROR) then Exit;//执行失败<br>&nbsp; &nbsp;Temp := TNetResourceArray(Buf);<br>&nbsp; &nbsp;for i := 0 to Count - 1 do//列举工作组的计算机名称<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;//获取工作组的计算机名称,+2表示删除"//",如//wangfajun=&gt;wangfajun<br>&nbsp; &nbsp; &nbsp;form1.combobox1.Items.Add(Temp^.lpRemoteName + 2);<br>&nbsp; &nbsp; &nbsp;inc(Temp);<br>&nbsp; &nbsp;end;<br>&nbsp;end;<br>&nbsp;Res := WNetCloseEnum(lphEnum);//关闭一次列举<br>&nbsp;if Res &lt;&gt; NO_ERROR then exit;//执行失败<br>&nbsp;Result := True;<br>&nbsp;FreeMem(Buf);<br>end;<br><br><br>还是不行!
 
唉,你得象大家保证,你是在有不止一台机子的网络上运行这个程序的先才行呀
 
我是只有一台机器运行这个程序!有什么问题么?
 
我在局域网里面,但是只有我一台机器运行这个程序!
 
你的工作组有几台机?你能从你的工作组中看到几台电脑?
 
to app2001,<br><br>所有!
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; ComboBox1: TComboBox;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>type<br>&nbsp; TNetResourceArray = ^TNetResource; &nbsp;//网络资源类型的数组<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 &lt;&gt; 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 &lt;&gt; 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 &lt;&gt; 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 &lt;&gt; 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 &lt;&gt; 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 &lt;&gt; 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>&nbsp; NetResource:TNetResource;<br>&nbsp; Buf : Pointer;<br>&nbsp; Count,BufSize,Res : DWord;<br>&nbsp; Ind : Integer;<br>&nbsp; lphEnum : THandle;<br>&nbsp; Temp:TNetResourceArray;<br>Begin<br>&nbsp; Result := False;<br>&nbsp; List.Clear;<br>&nbsp; FillChar(NetResource, SizeOf(NetResource), 0); &nbsp;//初始化网络层次信息<br>&nbsp; NetResource.lpRemoteName := @GroupName[1]; &nbsp; &nbsp; &nbsp;//指定工作组名称<br>&nbsp; NetResource.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;//类型为服务器(工作组)<br>&nbsp; NetResource.dwUsage := RESOURCEUSAGE_CONTAINER;<br>&nbsp; NetResource.dwScope := RESOURCETYPE_DISK; &nbsp; &nbsp; &nbsp;//列举文件资源信息<br>&nbsp; Res := WNetOpenEnum( RESOURCE_GLOBALNET, RESOURCETYPE_DISK,RESOURCEUSAGE_CONTAINER, @NetResource,lphEnum);<br>If Res &lt;&gt; NO_ERROR Then Exit; //执行失败<br>&nbsp;While True Do &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//列举指定工作组的网络资源<br>&nbsp; Begin<br>&nbsp; &nbsp;Count := $FFFFFFFF; //不限资源数目<br>&nbsp; &nbsp;BufSize := 8192; &nbsp; &nbsp;//缓冲区大小设置为8K<br>&nbsp; &nbsp;GetMem(Buf, BufSize);//申请内存,用于获取工作组信息,获取计算机名称<br>&nbsp; &nbsp;Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);<br>&nbsp; If Res = ERROR_NO_MORE_ITEMS Then break;//资源列举完毕<br>&nbsp; If (Res &lt;&gt; NO_ERROR) then Exit;//执行失败<br>&nbsp; &nbsp; Temp := TNetResourceArray(Buf);<br>&nbsp; &nbsp;For Ind := 0 to Count - 1 do//列举工作组的计算机名称<br>&nbsp; &nbsp; &nbsp;Begin<br>&nbsp; &nbsp; &nbsp; &nbsp;List.Add(Temp^.lpRemoteName);<br>&nbsp; &nbsp; &nbsp; &nbsp;Inc(Temp);<br>&nbsp; &nbsp; &nbsp;End;<br>&nbsp;End;<br>&nbsp;Res := WNetCloseEnum(lphEnum);//关闭一次列举<br>If Res &lt;&gt; NO_ERROR Then exit;//执行失败<br>&nbsp; Result:=True;<br>&nbsp; FreeMem(Buf);<br>end;<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<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>&nbsp; for j:=0 to ComputerList.Count-1 do<br>&nbsp; &nbsp; ComboBox1.Items.Add(ComputerList.Strings[j]);<br>end;<br>if ComboBox1.Items.Count&gt;0 then ComboBox1.ItemIndex:=0;<br>GroupList.Free;<br>ComputerList.Free;<br>end;<br><br>end.<br>
 
我将所有代码放出来了!大家看看吧!为什么我总是不行!<br><br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls, TFlatSpeedButtonUnit, Buttons;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; ComboBox1: TComboBox;<br>&nbsp; &nbsp; ComboBox2: TComboBox;<br>&nbsp; &nbsp; GroupBox1: TGroupBox;<br>&nbsp; &nbsp; RadioButton1: TRadioButton;<br>&nbsp; &nbsp; RadioButton2: TRadioButton;<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; SpeedButton1: TSpeedButton;<br>&nbsp; &nbsp; procedure RadioButton1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure RadioButton2Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure SpeedButton1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br><br><br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>&nbsp;implementation<br>function<br>NetMessageBufferSend(servername:PWideChar;msgname:PWideChar;<br>fromname:PWideChar;buf:PWideChar;buflen:DWORD):DWORD;stdcall;external 'netapi32.dll'<br><br>{$R *.dfm}<br>type<br>&nbsp;TNetResourceArray = ^TNetResource; &nbsp;//网络资源类型的数组<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 &lt;&gt; 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 &lt;&gt; 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 &lt;&gt; 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 &lt;&gt; 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 &lt;&gt; 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 &lt;&gt; 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>&nbsp;NetResource:TNetResource;<br>&nbsp;Buf : Pointer;<br>&nbsp;Count,BufSize,Res : DWord;<br>&nbsp;Ind : Integer;<br>&nbsp;lphEnum : THandle;<br>&nbsp;Temp:TNetResourceArray;<br>Begin<br>&nbsp;Result := False;<br>&nbsp;List.Clear;<br>&nbsp;FillChar(NetResource, SizeOf(NetResource), 0); &nbsp;//初始化网络层次信息<br>&nbsp;NetResource.lpRemoteName := @GroupName[1]; &nbsp; &nbsp; &nbsp;//指定工作组名称<br>&nbsp;NetResource.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;//类型为服务器(工作组)<br>&nbsp;NetResource.dwUsage := RESOURCEUSAGE_CONTAINER;<br>&nbsp;NetResource.dwScope := RESOURCETYPE_DISK; &nbsp; &nbsp; &nbsp;//列举文件资源信息<br>&nbsp;Res := WNetOpenEnum( RESOURCE_GLOBALNET, RESOURCETYPE_DISK,RESOURCEUSAGE_CONTAINER, @NetResource,lphEnum);<br>If Res &lt;&gt; NO_ERROR Then Exit; //执行失败<br>While True Do &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//列举指定工作组的网络资源<br>&nbsp;Begin<br>&nbsp; Count := $FFFFFFFF; //不限资源数目<br>&nbsp; BufSize := 8192; &nbsp; &nbsp;//缓冲区大小设置为8K<br>&nbsp; GetMem(Buf, BufSize);//申请内存,用于获取工作组信息,获取计算机名称<br>&nbsp; Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);<br>&nbsp;If Res = ERROR_NO_MORE_ITEMS Then break;//资源列举完毕<br>&nbsp;If (Res &lt;&gt; NO_ERROR) then Exit;//执行失败<br>&nbsp; &nbsp;Temp := TNetResourceArray(Buf);<br>&nbsp; For Ind := 0 to Count - 1 do//列举工作组的计算机名称<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; List.Add(Temp^.lpRemoteName);<br>&nbsp; &nbsp; &nbsp; Inc(Temp);<br>&nbsp; &nbsp; End;<br>End;<br>Res := WNetCloseEnum(lphEnum);//关闭一次列举<br>If Res &lt;&gt; NO_ERROR Then exit;//执行失败<br>&nbsp;Result:=True;<br>&nbsp;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>&nbsp;ZAppName: array[0..127] of char;<br>&nbsp;Hold: String;<br>&nbsp;Found: HWND;<br>begin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//防止程序多次运行<br>&nbsp;Hold := Application.Title;<br>&nbsp;Application.Title := 'OnlyOne'<br>&nbsp; &nbsp; + IntToStr(HInstance); // 暂时修改窗口标题<br>&nbsp;StrPCopy(ZAppName, Hold); // 原窗口标题<br>&nbsp;Found := FindWindow(nil, ZAppName); // 查找窗口<br>&nbsp;Application.Title := Hold; // 恢复窗口标题<br>&nbsp;if Found&lt;&gt;0 then begin<br>&nbsp; &nbsp;// 若找到则激活已运行的程序并结束自身<br><br>&nbsp; &nbsp;ShowWindow(Found, SW_RESTORE);<br>&nbsp; &nbsp;Application.Terminate;<br>&nbsp;end;<br><br><br>end;<br><br>procedure TForm1.SpeedButton1Click(Sender: TObject);<br>var<br>&nbsp; com1,com2:WideString;<br>&nbsp; a:string;<br>&nbsp; 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>&nbsp;for j:=0 to ComputerList.Count-1 do<br>&nbsp; &nbsp;ComboBox1.Items.Add(ComputerList.Strings[j]);<br>end;<br>if ComboBox1.Items.Count&gt;0 then ComboBox1.ItemIndex:=0;<br>GroupList.Free;<br>ComputerList.Free;<br>if &nbsp;RadioButton2.Checked =true then<br>begin<br>&nbsp; &nbsp;a:='command.com /c net send * '+combobox2.Text; &nbsp; //net send 命令<br>&nbsp; &nbsp;WinExec(PChar(a), SW_SHOWNORMAL);<br>&nbsp; &nbsp;ShowMessage('所有信息已经发送完毕!')<br>end<br>else<br>&nbsp; com2:=combobox2.Text ;<br>&nbsp; com1:=combobox1.Text ;<br>&nbsp; NetMessageBufferSend(NIL,PWidechar(com1),Nil,PWideChar(com2),Length(String(com2)));<br>&nbsp; ShowMessage('发往' + combobox1.Text + '的信息已经发出了')<br><br>end;<br><br>end.<br><br><br>
 

Similar threads

D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
897
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部