主题:[讨论]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和百度老师了.它们都给我很模糊的答案.给的都是如何写入注册表启动的.可是不是我要的答案,所以才来此群发帖.
望前辈们的指教!