📄 subsuperuserunit.~pas
字号:
AThread.Connection.Write('远程删除失败!该目录:'+#10#13+TheDirName+'不存在!'+EOL);
end;
except
end;
end;
//=================================目录创建 -----11
procedure DirCreateProc(AThread:TIdPeerThread);//======应用主线程
var
TheDir:String;
begin
try
TheDir:=AThread.Connection.ReadLn(EOL);
except
exit;
end;
LetSingle2.Acquire; //登记日志
RegUserOperation(AThread,'超级用户','目录创建',TheDir);
LetSingle2.Leave;
try
if DirectoryExists(TheDir) then
AThread.Connection.Write(TheDir+#10#13+
'该目录已经存在,请重新命名。'+EOL) else
if ForceDirectories(TheDir) then
AThread.Connection.Write('OK'+EOL) else
AThread.Connection.Write('请检查您是否有权限创建文件夹。'+EOL);
except
end;
end;
//=================================目录复制 -----12
procedure DirCopyProc(AThread:TIdPeerThread);
var
SourceDir,TargetDir:String;
SCopyThread:TServerCopyThread;
begin
SourceDir:=AThread.Connection.ReadLn(EOL);//读要复制的目录
TargetDir:=AThread.Connection.ReadLn(EOL);//读要复制到的目录下
SCopyThread:=TServerCopyThread.Create(AThread,SourceDir,TargetDir,'超级用户');
end;
//=================================远程执行 -----13
procedure RemoteFileOpenProc(AThread:TIdPeerThread);
var
TheFile:String;
begin
try
TheFile:=AThread.Connection.ReadLn(EOL);
except
exit;
end;
LetSingle2.Acquire; //登记日志
RegUserOperation(AThread,'超级用户','远程打开或执行',TheFile);
LetSingle2.Leave;
if FileExists(TheFile) then
ShellExecute(Application.Handle, 'OPEN',
PChar(TheFile),'','', SW_SHOWNORMAL) else
begin
if DirectoryExists(TheFile) then
ShellExecute(Application.Handle, 'OPEN',
PChar(TheFile),'','', SW_SHOWNORMAL) else
begin
try
AThread.Connection.Write('远程文件不存在,执行失败!'+EOL);
except
end;
exit;
end;
end;
try
AThread.Connection.Write('恭喜啦!远程命令已经执行!'+EOL);
except
end;
end;
//=================================文件属性 -----14
procedure GetFileAttrProc(AThread:TIdPeerThread);
var
TheFile:String;
sr:TSearchRec;
FileAttrs,iFCount:integer;
LocalFileTime:TFileTime;
DosFileTime : DWORD;
TheFCreateTime:String;
TheFWriteTime :string;
TheFAccessTime:string;
begin
try
TheFile:=AThread.Connection.ReadLn(EOL);
except
exit;
end;
LetSingle2.Acquire; //登记日志
RegUserOperation(AThread,'超级用户','查看文件属性',TheFile);
LetSingle2.Leave;
if FindFirst(TheFile,faAnyFile, sr) = 0 then
begin
//文件创建时间
FileTimeToLocalFileTime(sr.FindData.ftCreationTime,LocalFileTime);
FileTimeToDosDateTime(LocalFileTime,
LongRec(DosFileTime).Hi,LongRec(DosFileTime).Lo);
TheFCreateTime:=DateTimeToStr(FileDateToDateTime(DosFileTime));
//文件修改时间
TheFWriteTime:=DateTimeToStr(FileDateToDateTime(sr.Time));
//文件最后访问时间
FileTimeToLocalFileTime(sr.FindData.ftLastAccessTime,LocalFileTime);
FileTimeToDosDateTime(LocalFileTime,
LongRec(DosFileTime).Hi,LongRec(DosFileTime).Lo);
TheFAccessTime:=DateTimeToStr(FileDateToDateTime(DosFileTime));
try
AThread.Connection.WriteInteger(sr.Size);
AThread.Connection.Write(TheFCreateTime+EOL);
AThread.Connection.Write(TheFWriteTime+EOL);
AThread.Connection.Write(TheFAccessTime+EOL);
AThread.Connection.WriteInteger(sr.Attr);
except
FindClose(sr);
exit;
end;
end;
FindClose(sr);
end;
//=================================目录属性 -----15
procedure GetDirAttrProc(AThread:TIdPeerThread);
var
TheDirName :String;
TheDirSize :integer;//目录占用空间大小---要反馈1
TheFolderCount :integer;//子目录的个数 ---要反馈2
TheFilesCount :integer;//包含的文件数 ---要反馈3
TheDirAttr :integer;//目录属性 ---要反馈4
DirCreateTime :String; //目录创建时间 ---要反馈5
TheFileList :TStringList;
sr :TSearchRec;
begin
try
TheDirName:=AThread.Connection.ReadLn(EOL);//读目录名
except
exit;
end;
LetSingle2.Acquire; //登记日志
RegUserOperation(AThread,'超级用户','查看目录属性',TheDirName);
LetSingle2.Leave;
try
TheFileList:=TStringList.Create;
except
exit;
end;
TheDirSize:=0;
TheFolderCount:=0;
GetTheDirAttr(TheDirName,TheFileList,TheDirSize,TheFolderCount);
TheFilesCount:=TheFileList.Count;
TheFileList.Free;
TheDirName:=StrUtils.LeftStr(TheDirName,length(TheDirName)-1);
if FindFirst(TheDirName,faAnyFile, sr) = 0 then
begin
DirCreateTime:=DateTimeToStr(FileDateToDateTime(sr.Time));
TheDirAttr:=sr.Attr;
end;
FindClose(sr);
//----------------------------- 数据反馈 1--2--3---4
try
AThread.Connection.WriteInteger(TheDirSize);
AThread.Connection.Write(IntToStr(TheFilesCount)+'个文件,有子文件夹:'
+IntToStr(TheFolderCount)+'个'+EOL);
AThread.Connection.Write(DirCreateTime+EOL);
AThread.Connection.WriteInteger(TheDirAttr);
except
end;
end;
//==================统计目录文件大小与文件组成 -----16
procedure GetTheDirAttr(TheFPath:String;TheFList:TStringList;
Var TotalSize,TotalFolderCount:integer);
Var
sr: TSearchRec;
begin
if FindFirst(TheFPath+'*.*',faAnyFile, sr) = 0 then
begin
repeat
if (Sr.Attr<16) then
begin
TheFList.Add(TheFPath+Sr.Name);
TotalSize:=TotalSize+Sr.Size;
end;
if (Sr.Attr>=32) then
if (Sr.Attr<48) then
begin
TheFList.Add(TheFPath+Sr.Name);
TotalSize:=TotalSize+Sr.Size;
end;
if (Sr.Attr<32) and (Sr.Attr>=16) then
begin
if (Sr.Name<>'.') then
if (Sr.Name<>'..') then
begin
TotalFolderCount:=totalFolderCount+1;
GetTheDirAttr(TheFPath+Sr.Name+'\',TheFList,
TotalSize,TotalFolderCount);
end;
end;
if (Sr.Attr>=48) then
begin
if (Sr.Name<>'.') then
if (Sr.Name<>'..') then
begin
TotalFolderCount:=totalFolderCount+1;
GetTheDirAttr(TheFPath+Sr.Name+'\',TheFList,
TotalSize,TotalFolderCount);
end;
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
//==================目录属性更改-------------------- 17
procedure SetDirAttrProc(AThread:TIdPeerThread);
var
TheDirName:String;
TheAttr :Integer;
begin
try
TheDirName:=AThread.Connection.ReadLn(EOL);
TheAttr:=AThread.Connection.ReadInteger;
except
exit;
end;
LetSingle2.Acquire; //登记日志
RegUserOperation(AThread,'超级用户','目录属性更改',TheDirName);
LetSingle2.Leave;
try
if FileSetAttr(TheDirName,TheAttr)=0 then
AThread.Connection.Write(DatetimeTostr(now)+
' 操作成功,属性已经更改!'+EOL)
else
AThread.Connection.Write(DatetimeTostr(now)+
'对不起,操作失败,属性没有更改,请重新设置!'+EOL);
except
end;
end;
//==================文件属性更改-------------------- 18
procedure SetFileAttrProc(AThread:TIdPeerThread);
var
TheFileName:String;
TheAttr :Integer;
begin
try
TheFileName:=AThread.Connection.ReadLn(EOL);
TheAttr:=AThread.Connection.ReadInteger;
except
exit;
end;
LetSingle2.Acquire; //登记日志
RegUserOperation(AThread,'超级用户','文件属性更改',TheFileName);
LetSingle2.Leave;
Try
if FileSetAttr(TheFileName,TheAttr)=0 then
AThread.Connection.Write(DatetimeTostr(now)+
' 操作成功,属性已经更改!'+EOL)
else
AThread.Connection.Write(DatetimeTostr(now)+
'对不起,操作失败,属性没有更改,请重新设置!'+EOL);
except
end;
end;
//==================名称更改----------------------19
procedure TheRenameProc(AThread:TIdPeerThread);
var
TheOldName:string;
TheNewName:string;
begin
try
TheOldName:=AThread.Connection.ReadLn(EOL);
TheNewName:=AThread.Connection.ReadLn(EOL);
except
exit;
end;
LetSingle2.Acquire; //登记日志
RegUserOperation(AThread,'超级用户','名称更改',
'改'+TheOldName+' 为 '+TheNewName);
LetSingle2.Leave;
try
if FileExists(TheNewName) then
begin
AThread.Connection.Write('新文件名冲突,请选择其它文件名'+EOL);
exit;
end;
if DirectoryExists(TheNewName) then
begin
AThread.Connection.Write('新文件夹冲突,请选择其它名称!'+EOL);
exit;
end;
if RenameFile(TheOldName,TheNewName)=false then
AThread.Connection.Write('远程操作失败,请检查您是否有修改的权限。'+EOL) else
AThread.Connection.Write('远程操作成功啦,请继续其它操作。'+EOL);
except
end;
end;
//==================文件搜索----------------------20
procedure FileSearchProc(AThread:TIdPeerThread);
var
TheFileType:String;
TheFileSize:integer;
TheFilePath:string;
SearchThread:TSearchThread;
begin
try
TheFileType:=AThread.Connection.ReadLn(EOL); //接收搜索的文件类型
TheFileSize:=AThread.Connection.ReadInteger; //搜索的大小
TheFilePath:=AThread.Connection.ReadLn(EOL); //搜索的起始目录或文件夹
except
AThread.Free;
exit;
end;
//启动搜索线程开始搜索
try
SearchThread:=TSearchThread.Create(AThread,TheFileType,
TheFileSize,TheFilePath,'超级用户');
except
AThread.Connection.Disconnect;
AThread.Free;
end;
end;
//==================搜索下载----------------------21
procedure FSearchDLProc(AThread:TIdPeerThread);
var
TheFileName:String;
begin
try
TheFileName:=AThread.Connection.ReadLn(EOL);
except
exit;
end;
LetSingle2.Acquire; //登记日志
RegUserOperation(AThread,'超级用户','搜索下载',
'下载文件:'+TheFileName);
LetSingle2.Leave;
if TheFileName='去去去.去去去' then AThread.Connection.Disconnect;
try
if FileExists(TheFileName) then
begin
AThread.Connection.Write('OK'+EOL);
SendSearchFile(AThread,TheFileName);
end else
AThread.Connection.Write('文件不存在'+EOL);
except
end;
end;
//====================发送搜索文件-----------------22
procedure SendSearchFile(AThread:TIdPeerThread;TheFileName:String);
var
FromF: file of byte;
FileLen:integer;
NumRead, NumWritten: Integer;
Buf: array[1..32768] of Char;
begin
try
AssignFile(FromF,TheFileName);
FileMode:=0;
Reset(FromF);
Seek(FromF,0);
except
CloseFile(FromF);
exit;
end;
try
FileLen:=FileSize(FromF);
AThread.Connection.WriteInteger(FileLen);
except
CloseFile(FromF);
exit;
end;
try
repeat
AThread.Connection.OpenWriteBuffer;
BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
AThread.Connection.WriteBuffer(Buf,NumRead);
AThread.Connection.CloseWriteBuffer;
until (NumRead = 0);
except
end;
CloseFile(FromF);
end;
//====================命令行操作--------------------23
procedure CommandLineProc(AThread:TIdPeerThread);
//----------------------------输出定向
function GetDosOutput(const CommandLine:string): string;
var
SA: TSecurityAttributes;
SI: TStartupInfo;
PI: TProcessInformation;
StdOutPipeRead, StdOutPipeWrite: THandle;
WasOK: Boolean;
Buffer: array[0..255] of Char;
BytesRead: Cardinal;
WorkDir, Line: String;
begin
with SA do
begin
nLength := SizeOf(SA);
bInheritHandle := True;
lpSecurityDescriptor := nil;
end;
CreatePipe(StdOutPipeRead,StdOutPipeWrite,@SA,0);
try
with SI do
begin
FillChar(SI, SizeOf(SI), 0);
cb := SizeOf(SI);
dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
wShowWindow := SW_Hide;
hStdInput := GetStdHandle(STD_INPUT_HANDLE);
hStdOutput := StdOutPipeWrite;
hStdError := StdOutPipeWrite;
end;
WasOK := CreateProcess(nil, PChar(CommandLine), nil, nil, True,
HIGH_PRIORITY_CLASS, nil,
nil, SI, PI);
if CloseHandle(StdOutPipeWrite) then begin end;
if WasOK then
try
Line := '';
repeat
WasOK := ReadFile(StdOutPipeRead, Buffer, 255, BytesRead, nil);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -