抄别人的,我试过了,甚至可以查到指定IP的共享目录。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls, StdCtrls, Buttons,shellapi;
type
TNetResourceArray = ^TNetResource;//网络类型的数组
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Edit1: TEdit;
BitBtn1: TBitBtn;
ScrollBox1: TScrollBox;
ListBox1: TListBox;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
CheckBox1: TCheckBox;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Button1: TButton;
TrackBar1: TTrackBar;
Edit5: TEdit;
Timer1: TTimer;
StatusBar1: TStatusBar;
Image1: TImage;
Label7: TLabel;
procedure TrackBar1Change(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Label7Click(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Label7MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure CheckBox1Click(Sender: TObject);
private
{ Private declarations }
procedure WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo);//禁止窗口改变大小
message WM_GETMINMAXINFO;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
procedure TForm1.WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo); //enable change form size
begin
inherited;
with Msg.MinMaxInfo^ do begin
ptMinTrackSize.x:= Form1.width;
ptMaxTrackSize.x:= Form1.width;
ptMinTrackSize.y:= Form1.height;
ptMaxTrackSize.y:= Form1.height;
end;
end;
Function GetUserResource( UserName : string ) : Boolean;
Var
NetResource:TNetResource;
Buf
ointer;
Count,BufSize,Res
Word;
Ind : Integer;
lphEnum : THandle;
Temp : TNetResourceArray;
Begin
Result := False;
FillChar(NetResource, SizeOf(NetResource), 0);//初始化网络层次信息
NetResource.lpRemoteName := @UserName[1];//指定计算机名称
//获取指定计算机的网络资源句柄
Res := WNetOpenEnum( RESOURCE_GLOBALNET, RESOURCETYPE_ANY,
RESOURCEUSAGE_CONNECTABLE, @NetResource,lphEnum);
If Res <> NO_ERROR Then
begin
exit;//执行失败
end;
While True Do//列举指定工作组的网络资源
Begin
Count := $FFFFFFFF;//不限资源数目
BufSize := 8192;//缓冲区大小设置为8K
GetMem(Buf, BufSize);//申请内存,用于获取工作组信息
//获取指定计算机的网络资源名称
Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);
If Res = ERROR_NO_MORE_ITEMS Then break;//资源列举完毕
If (Res <> NO_ERROR) then Exit;//执行失败
Temp := TNetResourceArray(Buf);
For Ind := 0 to Count - 1 do
Begin
//获取指定计算机中的共享资源名称,+2表示删除"//",
form1.ListBox1.Items.Add(string(Temp^.lpRemoteName +2));
Inc(Temp);
End;
End;
Res := WNetCloseEnum(lphEnum);//关闭一次列举
If Res <> NO_ERROR Then
begin
exit;//执行失败
end;
Result := True;
FreeMem(Buf);
End;
{$R *.dfm}
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
timer1.Interval:=trackbar1.Position*1000;
edit5.Text:=inttostr(trackbar1.Position);
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
listbox1.Clear;
if not checkbox1.Checked then
begin
statusbar1.Panels[0].Text:='检测中.....';
if GetUserResource('//'+edit1.Text) then listbox1.Items.Add('找到共享资源');
statusbar1.Panels[0].Text:='检测完毕!!';
end
else
begin
statusbar1.Panels[0].Text:='稍候.....';
statusbar1.Update;
timer1.Enabled:=true;
end;
// listbox1.SetFocus;
listbox1.itemindex:=0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
timer1.Enabled:=false;
statusbar1.Panels[0].Text:='被用户强制停止';
statusbar1.Update;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
case Wnetcancelconnection('X:',False) of
0:statusbar1.Panels[0].Text:='成功断开';
50:statusbar1.Panels[0].Text:='函数不被支持';
8: statusbar1.Panels[0].Text:='系统内存不足';
59:statusbar1.Panels[0].Text:='网络发生错误';
487:statusbar1.Panels[0].Text:='无效指针';
87:statusbar1.Panels[0].Text:='无效网络名';
2250: statusbar1.Panels[0].Text:='无须断开的连接';
2401:statusbar1.Panels[0].Text:='断开的连接有打开的文件';
else
statusbar1.Panels[0].Text:='连接错误';
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
var
path_lsq
char;
begin
if ListBox1.Items.Count=0 then
application.MessageBox('共享资源中没有网络路径或是没有选中!!','玩命的警告',MB_ok+MB_Iconstop) else
begin
case Wnetcancelconnection('X:',False) of
0:statusbar1.Panels[0].Text:='成功断开';
50:statusbar1.Panels[0].Text:='函数不被支持';
8: statusbar1.Panels[0].Text:='系统内存不足';
59:statusbar1.Panels[0].Text:='网络发生错误';
487:statusbar1.Panels[0].Text:='无效指针';
87:statusbar1.Panels[0].Text:='无效网络名';
2250: statusbar1.Panels[0].Text:='无须断开的连接';
2401:statusbar1.Panels[0].Text:='断开的连接有打开的文件';
else
statusbar1.Panels[0].Text:='连接错误';
end;
case Wnetaddconnection(pchar('//'+listbox1.Items.Strings[listbox1.ItemIndex]),'111','X:') of
0:
begin
statusbar1.Panels[0].Text:='成功入侵,请察看你的资源管理器';
path_lsq:= pchar('explorer '+('//'+listbox1.Items.Strings[listbox1.ItemIndex]));
Winexec(path_lsq,SW_Show);
end;
50: statusbar1.Panels[0].Text:= '函数不被支持';
8: statusbar1.Panels[0].Text:='系统内存不足 ';
59: statusbar1.Panels[0].Text:='网络发生错误 ';
487: statusbar1.Panels[0].Text:='无效指针';
67: statusbar1.Panels[0].Text:='无效网络名';
1200:statusbar1.Panels[0].Text:='无效本地名';
85: statusbar1.Panels[0].Text:= '此连接已经建立,清先断开';
86:statusbar1.Panels[0].Text:='无效口令';
5:statusbar1.Panels[0].Text:='访问被拒绝';
else
statusbar1.Panels[0].Text:= '连接错误';
end;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
begin
statusbar1.Panels[0].Text:='正在检测网段.....';
statusbar1.Update;
if GetUserResource('//'+edit2.Text+'.'+edit3.Text) then
begin
listbox1.Items.Add('找到共享资源');
timer1.Enabled:=false;
end;
if edit3.Text=edit4.Text then
begin
statusbar1.Panels[0].Text:='检测完毕';
statusbar1.Update;
timer1.Enabled:=false;
end;
edit3.Text:=inttostr(strtoint(edit3.Text)+1);
edit3.Update;
end;
end;
procedure TForm1.Label7Click(Sender: TObject);
begin
shellexecute(handle,'open',pchar('http://10.231.52.10'),nil,nil,sW_shownormal);
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Label7.Font.Color:=rgb(0,0,0);
end;
procedure TForm1.Label7MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Label7.Font.Color:=rgb(0,0,255);
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if checkbox1.Checked then
begin
edit2.Enabled:=true;
edit3.Enabled:=true;
edit4.Enabled:=true;
edit1.Enabled:=false;
end
else
begin
edit2.Enabled:=false;
edit3.Enabled:=false;
edit4.Enabled:=false;
edit1.Enabled:=true;
end;
end;
end.