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

📄 unit1.pas

📁 用delphi写的杀毒软件的源程序
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  ShortDateFormat:= 'yyyy-mm-dd';
  Form1.Caption:= ProgramVer;

  //系统目录
  SetLength(WinDir, 1024);
  ExpandEnvironmentStrings('%windir%', @WinDir[1], 1024);
  WinDir:= Trim(PChar(WinDir))+'\';
  //system目录
  if Win32Platform = VER_PLATFORM_WIN32_NT then
   SystemDir:='system32\' else SystemDir:='system\';

  myReg := TRegistry.Create;
  myReg.RootKey:=HKEY_LOCAL_MACHINE;
  if Win32Platform = VER_PLATFORM_WIN32_NT then
  begin
   StrTmp:='\SOFTWARE\Microsoft\Windows NT\CurrentVersion';
   EnableDebugPrivilege;
  end else
  begin
   StrTmp:='\Software\Microsoft\Windows\CurrentVersion';
   Button10.Enabled:= False;
   Button11.Enabled:= False;
  end;

  if myReg.OpenKey(StrTmp,false) then
  begin
   Edit4.Text:=myReg.ReadString('RegisteredOwner');
   Edit5.Text:=myReg.ReadString('RegisteredOrganization');
  end;
  StrTmp:='\SOFTWARE\Classes\CLSID\{FB7199AB-79BF-11d2-8D94-0000F875C541}';
  if myReg.OpenKey(StrTmp,false) then
   CheckBox8.Checked:= False
  else begin
   CheckBox8.Enabled:= False;
   CheckBox8.Checked:= True;
  end;
  myReg.CloseKey;

  if myReg.OpenKey('\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management',false) then
   if myReg.ReadInteger('ClearPageFileAtShutdown')=0 then CheckBox12.Checked:=True;

  myReg.RootKey:=HKEY_CURRENT_USER;
  StrTmp:='\Software\Microsoft\Windows\CurrentVersion\Explorer';
  if myReg.OpenKey(StrTmp,false) then
   if myReg.ValueExists('DesktopProcess') then
    if myReg.ReadInteger('DesktopProcess')=1 then
     CheckBox9.Checked:= True else CheckBox9.Checked:= False;
  StrTmp:='\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced';
  if myReg.OpenKey(StrTmp,false) then
   if myReg.ValueExists('SeparateProcess') then
    if myReg.ReadInteger('SeparateProcess')=1 then
     CheckBox10.Checked:= True else CheckBox10.Checked:= False;
  StrTmp:='\Software\Microsoft\Windows\CurrentVersion\Explorer\BrowseNewProcess';
  if myReg.OpenKey(StrTmp,false) then
   if myReg.ValueExists('BrowseNewProcess') then
    if myReg.ReadString('BrowseNewProcess')='yes' then
     CheckBox11.Checked:= True else CheckBox11.Checked:= False;

  myReg.CloseKey;
  myReg.Free;

  PageControl1.ActivePageIndex:= 0;
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  myReg: TRegistry;
  myIniFile:TIniFile;
  StrTmp: String;
  buf: TStringList;
  m,n: Integer;
begin
  myReg:= TRegistry.Create;
  buf:= TStringList.Create;
  StrTmp:='Software\Microsoft\Windows\CurrentVersion\';
  m:=0;
  ListView1.Clear;

  myReg.RootKey:= HKEY_CURRENT_USER;
  if myReg.OpenKey(StrTmp+'Run', false) then
  begin
   myReg.GetValueNames(buf);
   for n:=0 to buf.Count-1 do
   begin
    with ListView1.Items.Insert(m) do
    begin
     Caption:=buf[n];
     SubItems.Add(myReg.ReadString(buf[n]));
     SubItems.Add('HKEY_CURRENT_USER\'+StrTmp+'Run\');
    end;
    inc(m);
   end;
  end;
  myReg.CloseKey;
  if myReg.OpenKey(StrTmp+'RunOnce', false) then
  begin
   myReg.GetValueNames(buf);
   for n:=0 to buf.Count-1 do
   begin
    with ListView1.Items.Insert(m) do
    begin
     Caption:=buf[n];
     SubItems.Add(myReg.ReadString(buf[n]));
     SubItems.Add('HKEY_CURRENT_USER\'+StrTmp+'RunOnce\');
    end;
    inc(m);
   end;
  end;
  myReg.CloseKey;
  
  myReg.RootKey:= HKEY_LOCAL_MACHINE;
  if myReg.OpenKey(StrTmp+'Run', false) then
  begin
   myReg.GetValueNames(buf);
   for n:=0 to buf.Count-1 do
   begin
    with ListView1.Items.Insert(m) do
    begin
     Caption:=buf[n];
     SubItems.Add(myReg.ReadString(buf[n]));
     SubItems.Add('HKEY_LOCAL_MACHINE\'+StrTmp+'Run\');
    end;
    inc(m);
   end;
  end;
  myReg.CloseKey;
  if myReg.OpenKey(StrTmp+'RunOnce', false) then
  begin
   myReg.GetValueNames(buf);
   for n:=0 to buf.Count-1 do
   begin
    with ListView1.Items.Insert(m) do
    begin
     Caption:=buf[n];
     SubItems.Add(myReg.ReadString(buf[n]));
     SubItems.Add('HKEY_LOCAL_MACHINE\'+StrTmp+'RunOnce\');
    end;
    inc(m);
   end;
  end;
  myReg.CloseKey;
  if myReg.OpenKey(StrTmp+'RunOnceEx', false) then
  begin
   myReg.GetValueNames(buf);
   for n:=0 to buf.Count-1 do
   begin
    with ListView1.Items.Insert(m) do
    begin
     Caption:=buf[n];
     SubItems.Add(myReg.ReadString(buf[n]));
     SubItems.Add('HKEY_LOCAL_MACHINE\'+StrTmp+'RunOnceEx\');
    end;
    inc(m);
   end;
  end;
  myReg.CloseKey;
  if myReg.OpenKey(StrTmp+'RunServices', false) then
  begin
   myReg.GetValueNames(buf);
   for n:=0 to buf.Count-1 do
   begin
    with ListView1.Items.Insert(m) do
    begin
     Caption:=buf[n];
     SubItems.Add(myReg.ReadString(buf[n]));
     SubItems.Add('HKEY_LOCAL_MACHINE\'+StrTmp+'RunServices\');
    end;
    inc(m);
   end;
  end;
  myReg.CloseKey;
  if myReg.OpenKey(StrTmp+'RunServicesOnce', false) then
  begin
   myReg.GetValueNames(buf);
   for n:=0 to buf.Count-1 do
   begin
    with ListView1.Items.Insert(m) do
    begin
     Caption:=buf[n];
     SubItems.Add(myReg.ReadString(buf[n]));
     SubItems.Add('HKEY_LOCAL_MACHINE\'+StrTmp+'RunServicesOnce\');
    end;
    inc(m);
   end;
  end;

  myIniFile:= Tinifile.Create('win.ini');
  if myIniFile.ReadString('windows','load','')<>'' then
  begin
   with ListView1.Items.Insert(m) do
   begin
    Caption:='win.ini(load)';
    SubItems.Add(myIniFile.ReadString('windows','load',''));
    SubItems.Add('inifile ');
   end;
   inc(m);
  end;
  if myIniFile.ReadString('windows','run','')<>'' then
  begin
   with ListView1.Items.Insert(m) do
   begin
    Caption:='win.ini(run)';
    SubItems.Add(myIniFile.ReadString('windows','run',''));
    SubItems.Add('inifile ');
   end;
  end;
  
  myIniFile.Free;
  myReg.CloseKey;
  myReg.Free;
  buf.Free;
end;

procedure TForm1.ListView1Change(Sender: TObject; Item: TListItem;
  Change: TItemChange);
var
 StrTmp: String;
begin
 Label6.Caption:='';
 if ListView1.ItemIndex>-1 then
 begin
  StrTmp:=Item.SubItems[1]+Item.Caption;
  Label6.Hint:=StrTmp;
  StrTmp:=copy(Item.SubItems[1]+Item.Caption,1,45);
  StrTmp:=StrTmp+#13#10+copy(Item.SubItems[1]+Item.Caption,46,length(Item.SubItems[1]+Item.Caption));
  Label6.Caption:=StrTmp;
 end;
end;

procedure TForm1.Button5Click(Sender: TObject);
var
 myReg: TRegistry;
 myIniFile:TIniFile;
 regKey: String;
begin
 if ListView1.SelCount<1 then Abort;

 myReg:= TRegistry.Create;
 regKey:= '';

 if copy(ListView1.Selected.SubItems[1],1,18)='HKEY_LOCAL_MACHINE' then
 begin
  myReg.RootKey:= HKEY_LOCAL_MACHINE;
  regKey:=copy(ListView1.Selected.SubItems[1],19,length(ListView1.Selected.SubItems[1]));
 end else if copy(ListView1.Selected.SubItems[1],1,17)='HKEY_CURRENT_USER' then
 begin
  myReg.RootKey:= HKEY_CURRENT_USER;
  regKey:=copy(ListView1.Selected.SubItems[1],18,length(ListView1.Selected.SubItems[1]));
 end;

 if regKey<>'' then
  if myReg.OpenKey(regKey, false) then
   if myReg.ValueExists(ListView1.Selected.Caption) then
    myReg.DeleteValue(ListView1.Selected.Caption);

 myIniFile:=Tinifile.create('win.ini');
 if ListView1.Selected.SubItems[1]='inifile ' then
 begin
  if ListView1.Selected.Caption='win.ini(run)' then
   myIniFile.WriteString('windows','run','');
  if ListView1.Selected.Caption='win.ini(load)' then
   myIniFile.WriteString('windows','load','');
 end;

 ListView1.Selected.Delete;
 myIniFile.Free;
 myReg.CloseKey;
 myReg.Free;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
 SaveDialog1.DefaultExt:= 'reg';
 SaveDialog1.Filter:= '*.reg|*.reg';
 SaveDialog1.FileName:= DateTimeToStr(Date);
 if SaveDialog1.Execute then
 begin
  if CheckBox7.Checked then
   WinExecAndWait32('regedit.exe /e '+SaveDialog1.FileName,0)
   else WinExecAndWait32('regedit.exe /e '+SaveDialog1.FileName+' "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer"',0);
  ShowMessage('备份注册表完成!');
 end;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
 OpenDialog1.DefaultExt:= 'reg';
 OpenDialog1.Filter:= '*.reg|*.reg';
 if OpenDialog1.Execute then
 begin
  WinExecAndWait32('regedit.exe /c '+OpenDialog1.FileName,-1);
  ShowMessage('恢复注册表完成!');
 end;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
 SHChangeNotify(SHCNE_ASSOCCHANGED,SHCNF_IDLIST+SHCNF_FLUSH,nil,nil);
 Edit6.Text:='刷新系统完成!';
end;

procedure TForm1.Button0Click(Sender: TObject);
begin
 SaveDialog1.DefaultExt:= 'txt';
 SaveDialog1.Filter:= '*.txt|*.txt';
 SaveDialog1.FileName:= 'c:\backup';
 if SaveDialog1.Execute then
 begin
  WinExecAndWait32('cmd /c netsh interface ip dump >'+SaveDialog1.FileName,0);
  Edit6.Text:='导出网络设置完成!';
 end;
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
 OpenDialog1.DefaultExt:= 'txt';
 OpenDialog1.Filter:= '*.txt|*.txt';
 if OpenDialog1.Execute then
 begin
  WinExec(PChar('cmd /c netsh -f '+OpenDialog1.FileName),1);
  Edit6.Text:='导入网络设置完成!';
 end;
end;

procedure TForm1.Button12Click(Sender: TObject);
var
 Reg: TRegistry; 
 strDataRet, strDataRet2: String;
 success: DWORD;
begin
 //重置图标缓冲
 Edit6.Text:='正在运行重建缓存...';
 Application.ProcessMessages;
 Reg := TRegistry.Create;
 Reg.RootKey := HKEY_CURRENT_USER;
 if Reg.OpenKey('\Control Panel\Desktop\WindowMetrics',False) then
 begin
  strDataRet:= Reg.ReadString('Shell Icon Size');
  strDataRet2:= IntToStr(StrToInt(strDataRet)+1);
  Reg.WriteString('Shell Icon Size',strDataRet2);

  SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS,
   0, SMTO_ABORTIFHUNG, 10000, success);

  Reg.WriteString('Shell Icon Size',strDataRet);
 end;

 SetFileAttributes(PChar(WinDir+'shelliconcache'),FILE_ATTRIBUTE_ARCHIVE);
 if FileExists('shelliconcache') then DeleteFile('shelliconcache');
 SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS,
  0, SMTO_ABORTIFHUNG, 10000, success);

 Reg.CloseKey;
 Reg.Free;
 sleep(1000);
 SetFileAttributes(PChar(WinDir+'ttfcache'),FILE_ATTRIBUTE_ARCHIVE);
 if FileExists('ttfcache') then DeleteFile('ttfcache');
 Edit6.Text:='重建缓存完成!';
end;

//显示星号密码
procedure TForm1.Button9Click(Sender: TObject);
 function EnumChildWindowsProc(hwnd: Integer; lparam: Longint): Boolean; stdcall;
 begin
//  PostMessage(hwnd, EM_SETPASSWORDCHAR, longint('*'), 0);
  PostMessage(hwnd, EM_SETPASSWORDCHAR, longint(0), 0);
  InvalidateRgn(hwnd, 0, True);
  Result := True;
 end;
var
 Window_Handle: Integer;
begin
 Window_Handle := GetWindow(Application.Handle, GW_HWNDFIRST);
 while Window_Handle <> 0 do
 begin
  if Window_Handle <> 0 then
   EnumChildWindows(Window_Handle, @EnumChildWindowsProc,0);
  Window_Handle := GetWindow(Window_Handle, GW_HWNDNEXT);
 end;
end;

//内存整理
procedure TForm1.Button13Click(Sender: TObject);
var
 ms: TMemoryStatus;
 TotalMem: Longint;

 tab : array [0..1024] of pointer;
 i : integer;
 p : pointer;
begin
 if Running then Exit;
 Running:= True;
 Edit6.Text:='正在整理内存中...';

 ms.dwLength:=sizeof(ms);
 GlobalMemoryStatus(ms);
 TotalMem:=(ms.dwTotalPhys shr 20) + 1;
 Form1.Caption:= IntToStr(totalmem);
 if TotalMem>1024 then TotalMem:=1024;
 for i:=0 to TotalMem do tab[i]:=nil;
 for i:=0 to TotalMem-1 do
 begin
  p:=VirtualAlloc(nil, 1024*1024, MEM_COMMIT,PAGE_READWRITE+PAGE_NOCACHE);
  tab[i]:=p;
  asm
   pushad
   pushfd
   mov   edi, p
   mov   ecx, 1024*1024/4
   xor   eax, eax
   cld
   repz  stosd
   popfd
   popad
  end;
  Application.ProcessMessages;
 end;
 for i:=0 to TotalMem-1 do
 begin
  VirtualFree(Tab[i], 0, MEM_RELEASE);
  Application.ProcessMessages;
 end;

 Running:= False;
 Edit6.Text:='内存整理完成!';
end;

procedure TForm1.Button14Click(Sender: TObject);
begin
 WinExec(PChar('notepad.exe '+WinDir+'\win.ini'),3);
end;

procedure TForm1.Button15Click(Sender: TObject);
begin
 WinExec(PChar('notepad.exe '+WinDir+'\system.ini'),3);
end;

end.

⌨️ 快捷键说明

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