回 帖 发 新 帖 刷新版面

主题:[讨论]Delphi注册表开机如何指定到Windows\System32\下的新程序?


Function GetWinDir: String; //自定义函数
var
Buf:array[0..MAX_PATH] of char;
begin
     GetSystemDirectory(Buf,MAX_PATH);
     Result:= Buf;
     if Result[Length(Result)]<>'\' then Result := Result + '\';
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  Reg:TRegistry;
  myname:string;
begin
     myname:=ExtractFilename(Application.Exename);   //获得文件名
     if application.Exename <> GetWindir + myname then    //判断程序是否在Windows\System32\
begin
     Copyfile(pchar(application.Exename),pchar(GetWindir + myname),False);   //将自己拷贝到Windows\System32\下
     Winexec(pchar(GetWindir + myname),sw_hide);    //运行Windows\System32\下的新程序,不运行也可以!
     application.Terminate;    //退出旧程序
end;

begin
  try
    Reg:=TRegistry.Create;
    Reg.RootKey:=HKEY_LOCAL_MACHINE;
    if Reg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run',True) then
begin
    Reg.WriteString('123'+(GetWindir + myname));   //主要是这行错误,如何把Run里的123键的键值指向Windows\System32\下的新程序?
    Reg.CloseKey;
    Reg.Free;
    end;
    except
end;
end;
end.

有了Google和百度老师使我最近进步了不少!可是我问过Google和百度老师了.它们都给我很模糊的答案.给的都是如何写入注册表启动的.可是不是我要的答案,所以才来此群发帖.
望前辈们的指教!

回复列表 (共1个回复)

沙发

多年中小型项目开发经验,熟悉VB,VBA,Delphi和.NET平台,承接各种软件编写业务,
信誉第一,质量保证,售后完善,如有需要请联系QQ:3 8 3 1 4 7 8 1 8 请注明:pfan

我来回复

您尚未登录,请登录后再回复。点此登录或注册