📄 searchhostthreadunit.pas
字号:
begin
MyNode.ImageIndex :=15;
MyNode.SelectedIndex :=15;
end;
end
else
begin
MyNode.ImageIndex :=26;
MyNode.SelectedIndex :=26;
end;
end;
end;
procedure TSearchHostThread.BeFound;
begin
with MainForm do
begin
//ListBox1.Items.Add(MyHost+inttostr(handle)); ///
if isWinNT then
begin
MyNode.ImageIndex :=29;
MyNode.SelectedIndex :=29;
end;
if NoPassWordChicken then
begin
MyNode.ImageIndex :=110;
MyNode.SelectedIndex :=110;
end;
MyNode.Expand(false);
end;
end;
//-------------------------------------------------------------
function WinExecAndWait32(FileName:String; Visibility : integer):integer;
var
zAppName : array[0..512] of char;
zCurDir : array[0..255] of char;
WorkDir : String;
StartupInfo : TStartupInfo;
ProcessInfo : TProcessInformation;
hStdIn : THandle; // standard input handle
irMacroBuf : INPUT_RECORD; // array of input events
dwBytesWritten: DWORD;
begin
SetConsoleTitle('s');
StrPCopy(zAppName,FileName);
//MainForm.Caption := zappname;
GetDir(0,WorkDir);
StrPCopy(zCurDir,WorkDir);
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
StartupInfo.cb := Sizeof(StartupInfo);
hStdIn := StartupInfo.hStdInput;
StartupInfo.hStdInput := hStdIn;
StartupInfo.lpTitle := @zAppName;
StartupInfo.dwFlags := StartupInfo.dwFlags or STARTF_USESTDHANDLES;
WriteConsoleInput(hStdIn,irMacroBuf,1,dwBytesWritten);
StartupInfo.dwFlags := StartupInfo.dwFlags or STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := Visibility;
if not CreateProcess(nil,
zAppName, { pointer to command line string }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
false, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name }
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo) then Result := -1 { pointer to PROCESS_INF }
else begin
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
Result:=1;
end;
end;
//-------------------------------------------------------------
procedure TSearchHostThread.Execute;
var
EnumHandle : THandle;
DirRS : TNetResource;
Buf : Array[1..500] of TNetResource;
BufSize : DWord;
Entries : DWord;
Result : Integer;
CmdStr : string;
EverFoundDir : boolean;
SearchRec : TSearchRec;
DiskName : Char;
Found : integer;
s : string;
i: integer;
begin
//hFlag := 12345;
if stop then exit;
if terminated then exit;
//Synchronize(AddToHistory); //add to history
FileList := TStringList.Create;
SizeList := TStringList.Create;
EverFoundDir:=false;
NeedLogin:=false;
NeedPassWord:=false;
isWinNT:=false;
NoShareDir:=false;
MyHost := MyHost + #0;
FillChar(DirRS, SizeOf(DirRS) , 0);
With DirRS do begin
dwScope := 2;
dwType := 3;
dwDisplayType := 1;
dwUsage := 2;
lpRemoteName := @MyHost[1];
end;
Result := WNetOpenEnum( RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
@DirRS,
EnumHandle );
if Result<>NO_ERROR then
case Result of
WN_EXTENDED_ERROR: beep;//showmessage('WN_EXTENDED_ERROR');
WN_NOT_LOGGED_ON: beep;//showmessage('WN_NOT_LOGGED_ON');
WN_ACCESS_DENIED:
begin
isWinNT:=true; // NT system, haven't login before.
//---------------need login-------------
//showmessage('WN_ACCESS_DENIED');
//WNetGetUser(pchar(host),pchar('guest'),);
{登录计算机的方法
WinExec(Pchar('net use \\computername password /user:username',sw_Hide);
注销计算机的方法
WinExec(Pchar('net use \\computername /delete',sw_Hide);}
PassWord := '';
User := 'guest';
Synchronize(GetUserPassWord);
CmdStr := 'net use ' + trim(MyHost) + ' ' + PassWord;
CmdStr := CmdStr + ' /user:' + User + #0;
WinExecAndWait32(CmdStr,0);
Result := WNetOpenEnum( RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
@DirRS,
EnumHandle );
//--------------------05.11.3------------------
// guess
//
if Result = WN_ACCESS_DENIED then
begin
for i := 0 to ConfigForm.lvMountList.Items.Count-1 do
begin
s := ConfigForm.lvMountList.Items[i].Caption;
if s = '*' then
begin
User := ConfigForm.lvMountList.Items[i].SubItems[0];
//PassWord := ConfigForm.lvMountList.Items[i].SubItems[1];
PassWord := ConfigForm.SharePassList.Strings[i];
CmdStr := 'net use ' + trim(MyHost) + ' ' + PassWord;
CmdStr := CmdStr + ' /user:' + User + #0;
WinExecAndWait32(CmdStr,0);
Result := WNetOpenEnum( RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
@DirRS,
EnumHandle );
if Result = NO_ERROR then break;
end;
end;
end;
//---------------------------------------------
//========no password chickent test=======
if ConfigForm.cbNoPass.Checked then
begin
if Result = WN_ACCESS_DENIED then
begin
CmdStr := 'net use ' + trim(MyHost);
WinExecAndWait32(CmdStr,0);
//Windows.MessageBox(0,pchar('Chicken test!'), '', 0);
end;
end;
//========================================
if Result=WN_ACCESS_DENIED then NeedLogin:=true;
end;
WN_NOT_AUTHENTICATED :beep;//showmessage('WN_NOT_AUTHENTICATED');
end;//end of case
if (Result=NO_ERROR) then NoShareDir:=true;
//========no password chickent test=======
NoPassWordChicken := false;
if ConfigForm.cbNoPass.Checked then
begin
//Windows.MessageBox(0,pchar('Chicken test!'), '', 0);
if FindFirst(trim(MyHost) + '\c$\*.*', faAnyFile, SearchRec)=0
then NoPassWordChicken := true;
FindClose(SearchRec);
{if NoPassWordChicken
then Windows.MessageBox(0,pchar('Chicken found!' + trim(MyHost) + '\c$\*.*'), '', 0);}
end;
//========================================
if (NoPassWordChicken) then
begin
DiskName := 'c';
MyDir := Trim(MyHost) + '\' + DiskName + '$';
s := MyDir + '\*.*';
//Windows.MessageBox(0, pchar(MyDir), '', 0);
Found := FindFirst(s, faAnyFile, SearchRec);
FindClose(SearchRec);
while Found=0 do
begin
//Windows.MessageBox(0, pchar(MyDir), '', 0);
bPrinter := false;
Synchronize(AddDirNode);
FileList.Clear;
SizeList.Clear;
EverFoundDir := true;
findf(MyDir);
Synchronize(AddDir);
DiskName := char(ord(DiskName)+1);
MyDir := Trim(MyHost) + '\' + DiskName + '$';
s := MyDir + '\*.*';
Found := FindFirst(s, faAnyFile, SearchRec);
FindClose(SearchRec);
if ord(DiskName) < ord('h') then Found := 0;
end;
end
else
if Result= NO_ERROR then
begin
Repeat
//showmessage('no error');
Entries := 1;
BufSize := SizeOf(Buf);
Result := WNetEnumResource( EnumHandle,Entries,@Buf,BufSize );
If (Result = NO_ERROR) and (Entries = 1) then
begin
MyDir := StrPas(Buf[1].lpRemoteName);
if Buf[1].dwType = RESOURCETYPE_PRINT then bPrinter:= true
else bPrinter := false;
EverFoundDir := true;
Synchronize(AddDirNode);
//-------------------------------------------------
//############!!!
FileList.Clear;
SizeList.Clear;
if not bPrinter then if bAutoSearch then findf(MyDir);
//-------------------------------------------------
Synchronize(AddDir);
end ; //zw
if stop then exit;
if terminated then exit;
Until (Entries <> 1) or (Result <> NO_ERROR);
end;
if EverFoundDir then NoShareDir:=false;
WNetCloseEnum( EnumHandle );
if (not EverFoundDir) then Synchronize(NotFound) else Synchronize(BeFound);
Synchronize(AddToHistory); //add to history ////
FileList.Free;
SizeList.Free;
if terminated then exit;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -