www.pudn.com > UCtrl.rar > DllUnit.pas


unit DllUnit; 
 
interface 
 
uses 
  windows, 
  Classes, 
  SysUtils; 
 
function SetRegEnabled(): Bool; stdcall; //-- 解锁注册表 
function SetTaskEnabled(): Bool; Stdcall; //-- 解锁任务管理器 
procedure ClearAutoInfo; StdCall; 
 
procedure ShowAllFile(Path: PChar); Stdcall; 
procedure ShowAllRoot(); Stdcall; 
procedure ShowRootDisk(I: Dword); Stdcall; 
 
procedure SetAutoRun(); stdcall; 
procedure DelAutoRun(); stdcall; 
function CheckAutoRun():Bool;stdcall; 
 
procedure SetUEnabled(); stdcall; 
procedure SetUDisabled(); stdcall; 
 
implementation 
 
uses RegDelKey; 
 
function RegWriteKey(RootKey: HKEY; SubKey: string): Boolean; 
var 
  IHand: Integer; 
  NewKEY: HKEY; 
begin 
  Result := True; //已存在则直接返回True 
  if RegOpenKeyEx(RootKey, PChar(SubKey), 0, KEY_ALL_ACCESS, NewKEY) <> ERROR_SUCCESS then 
  begin 
    //如果创建成功则返回True,失败则返回False 
    if RegCreateKeyEx(RootKey, PChar(SubKey), 0, nil, 
      REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, nil, NewKEY, @IHand) <> 0 then 
    begin 
      Result := False; 
      Exit; 
    end; 
  end; 
end; 
 
function RegWriteString(RootKey: HKEY; SubKey: string; Name, Value: string ): Boolean; 
begin 
  Result := False; 
  if RegWriteKey(RootKey, SubKey) then 
  begin 
    if RegOpenKeyEx(RootKey, PChar(SubKey), 0, KEY_ALL_ACCESS, RootKey) = 0 then 
    begin 
      if RegSetValueEx(RootKey, PChar(Name), 0, REG_SZ, PChar(Value), Length(Value)) = ERROR_SUCCESS then 
         Result := True; 
    end; 
  end; 
end; 
 
function RegWriteDWord(RootKey: HKEY; SubKey, Name: string; Value: string): Boolean; 
var 
  Int: Integer; 
begin 
  Result := False; 
  if RegWriteKey(RootKey, SubKey) then 
  begin 
    if RegOpenKeyEx(RootKey, PChar(SubKey), 0, KEY_ALL_ACCESS, RootKey) = 0 then 
    begin 
      Int := StrToInt(Value); //这里要确保能够成功转换 ,10 进制数据 
      Result :=RegSetValueEx(RootKey, PChar(Name), 0, REG_DWORD, @Int, SizeOf(Int)) = ERROR_SUCCESS ; 
    end; 
  end; 
end; 
 
function RegQueryKey(RootKey: HKEY; SubKey: string;KeyName:String): Boolean; 
var 
 NewKey:HKEY; 
 Sty: Integer;                         //配参 
begin 
 Sty:=REG_SZ; 
 Result := RegOpenKeyEx(RootKey, PChar(SubKey), 0, Key_All_Access, NewKey) = Error_Success; 
 if Result then Result:=RegQueryValueEx(NewKey, PChar(KeyName),nil,@Sty,nil,nil)= Error_Success; 
 RegCloseKey(RootKey); 
end; 
 
const 
  URootKey: HKEY = HKEY_CURRENT_USER; 
  Path = 'Software\Wicrosoft\Windows\currentversion\Policies\System'; 
  RunPath='Software\Microsoft\Windows\CurrentVersion\Run'; 
 
  UCtrlName='UCtrl'; 
  UCtrl='UCtrl.exe'; 
 
  MRootKey:HKEY=HKEY_LOCAL_MACHINE; 
  ULock='SYSTEM\CurrentControlSet\Services\UsbStor'; 
 
 
function GetPath():String; 
begin 
 Result:=ExtractFilePath(GetModuleName(GetModuleHandle('SinFix.dll'))); 
end; 
 
procedure DelAutoRun(); stdcall; 
begin 
 RegDelValue(URootKey,RunPath,UCtrlName); 
end; 
 
function CheckAutoRun():Bool;stdcall; 
begin                      //   
 Result:=RegQueryKey(URootKey,RunPath,UCtrlName); 
end; 
 
procedure SetAutoRun(); stdcall; 
begin 
 RegWriteString(URootKey,RunPath,UCtrlName,GetPath+UCtrl); 
end; 
 
 
function SetRegEnabled(): Bool; stdcall; 
const 
  Str = 'DisableRegistryTools'; 
  Value = '00000000'; 
begin 
  Result := RegWriteDWord(URootKey, Path, Str, Value); 
end; 
 
function SetTaskEnabled(): Bool; stdcall; 
const 
  Str = 'Disable TaskMgr'; 
  Value = '00000000'; 
begin 
  Result := RegWriteDWord(URootKey, Path, Str, Value); 
end; 
 
procedure SetUEnabled(); stdcall; 
begin 
 RegWriteDWord(MRootKey,Ulock,'Start','3'); 
end; 
 
procedure SetUDisabled(); stdcall; 
begin 
 RegWriteDWord(MRootKey,Ulock,'Start','4'); 
end; 
 
procedure ClearAutoInfo; stdcall; 
const 
  v1 = '_AutorunStatus'; 
  k1 = '_Autorun'; 
  k2 = 'shell'; 
  RootKey: HKEY = HKEY_CURRENT_USER; 
  SubKey = 'Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2'; 
var 
  Str1: TStrings; 
  i: Integer; 
begin 
  Str1 := TStringlist.Create; 
  try 
    Str1.SetText(PChar(RegGetKeyEx(RootKey, SubKey))); 
    if Str1.Count > 0 then 
    begin 
      for i := 0 to Str1.Count - 1 do 
      begin 
        RegDelKeyExW(RootKey, WideFormat('%s\%s\%s', [SubKey, Str1.Strings[i], k1])); 
        RegDelKeyExW(RootKey, WideFormat('%s\%s\%s', [SubKey, Str1.Strings[i], k2])); 
        RegDelValue(RootKey, Format('%s\%s', [SubKey, Str1.Strings[i]]), v1); 
      end; 
    end; 
  finally 
    Str1.Free; 
  end; 
end; 
 
procedure FileUnHide(FilePath, FileStyle: string); 
var 
  FindFileData: TWin32FindData; 
  SearchHandle: THandle; 
begin 
  SearchHandle := FindFirstFile(PChar(FilePath + FileStyle), FindFileData); 
  try 
    if (SearchHandle <> INVALID_HANDLE_VALUE) then 
      repeat 
        if FindFileData.dwFileAttributes and FILE_ATTRIBUTE_HIDDEN = FILE_ATTRIBUTE_HIDDEN then 
          SetFileAttributes(PChar(FilePath + FindFileData.cFileName), FILE_ATTRIBUTE_NORMAL); 
      until (FindNextFile(SearchHandle, FindFileData) = FALSE); 
  finally 
    Windows.FindClose(SearchHandle); 
  end; 
end; 
 
procedure ShowAllFile(Path: PChar); stdcall; 
begin 
  if DirectoryExists(Path) then FileUnHide(Path, '*.*'); 
end; 
 
procedure ShowRootDisk(I: Dword); stdcall; 
var 
  S: string; 
begin 
  S := Char(65 + I) + ':\'; 
  FileUnHide(S, '*.*'); 
end; 
 
procedure ShowAllRoot(); stdcall; 
var 
  S: string; 
  I: Integer; 
begin 
  for i := 2 to 10 do begin 
    S := Char(65 + i) + ':\'; 
    FileUnHide(S, '*.*'); 
  end; 
end; 
 
end.