关于注册表问题(50分)

  • 主题发起人 主题发起人 lornsidezhao
  • 开始时间 开始时间
L

lornsidezhao

Unregistered / Unconfirmed
GUEST, unregistred user!
我想把自己本身的.exe 文件复制到指定目录,再把信息添加到注册表上去,让这个.exe文件每次启动都运行,怎么添加。
 
写到这个下面<br>HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Run
 
unit Capture_main;<br>interfaceuses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs,ExtCtrls, StdCtrls,registry,WinProcs;<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp; procedure WMQueryEndSession (var Message: TMessage);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;message WM_QUERYENDSESSION ;<br>&nbsp; end;<br>var<br>&nbsp; Form1: TForm1;<br>implementation<br>{$R *.dfm}<br>procedure TForm1.FormCreate(Sender: TObject);<br>var &nbsp;Reg: Tregistry;<br>begin<br>&nbsp; RegisterServiceProcess( GetCurrentProcessID, 1 );<br>&nbsp; Reg := Tregistry.Create ;<br>&nbsp; Reg.RootKey := HKEY_LOCAL_MACHINE;<br>&nbsp; if not reg.KeyExists('SOFTWARE/monitor')<br>&nbsp;then begin<br>&nbsp; &nbsp; Reg.CreateKey ('SOFTWARE/monitor');<br>&nbsp; &nbsp; Reg.Writestring('AutoRun', 'true');<br>&nbsp; &nbsp; Reg.OpenKey('SOFTWARE/Microsoft/Windows/CurrentVersion/Run',true);<br>&nbsp; &nbsp; Reg.WriteString('monitor_server',application.ExeName );<br>&nbsp; end;<br>&nbsp; Reg.CloseKey;<br>&nbsp; Reg.Free;<br>&nbsp; &nbsp;end;<br>procedure TForm1.WMQueryEndSession (var Message: TMessage);<br>var<br>&nbsp; Reg: Tregistry;<br>begin<br>&nbsp; Reg := Tregistry.Create ;<br>&nbsp; Reg.RootKey := HKEY_LOCAL_MACHINE;<br>&nbsp; Reg.OpenKey ('SOFTWARE/monitor',true);<br>&nbsp; if Reg.ReadString('AutoRun') = 'true' then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Reg.CloseKey;<br>&nbsp; &nbsp; &nbsp; Reg.OpenKey('SOFTWARE/Microsoft/Windows/CurrentVersion/Run', true);<br>&nbsp; &nbsp; &nbsp; Reg.WriteString('monitor_server',application.ExeName );<br>&nbsp; &nbsp; &nbsp; Reg.CloseKey;<br>&nbsp; &nbsp; &nbsp; Reg.Free;<br>&nbsp; &nbsp; end;<br>&nbsp; Form1.Close;<br>end;<br>end.
 
uses Registry;<br><br>function Get_AutoRun_Status:Boolean;<br>begin<br>&nbsp; with TRegistry.Create do<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; RootKey:=HKEY_LOCAL_MACHINE; &nbsp;//or HKEY_CURRENT_USER<br>&nbsp; &nbsp; &nbsp; OpenKey('Software/Microsoft/Windows/CurrentVersion/Run',true);<br>&nbsp; &nbsp; &nbsp; result:=ValueExists('your soft Name');<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; free;<br>&nbsp; end;<br>end;<br><br>procedure Set_AutoRun(const value:Boolean;const Path:string);<br>begin<br>&nbsp; with TRegistry.Create do<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; RootKey:=HKEY_LOCAL_MACHINE;<br>&nbsp; &nbsp; &nbsp; OpenKey('Software/Microsoft/Windows/CurrentVersion/Run',true);<br>&nbsp; &nbsp; &nbsp; case value of<br>&nbsp; &nbsp; &nbsp; &nbsp; true : WriteString('your soft Name',Path);<br>&nbsp; &nbsp; &nbsp; &nbsp; false: DeleteValue('your soft Name');<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; free;<br>&nbsp; end;<br>end;<br><br>//调用:<br>在你的程序中先调用Get_AutoRun_Status<br>如果返回false<br>则<br>Set_AutoRun(true,Path);<br>//path是你的程序路径加文件名<br><br>
 
你可以做一个安装程序啊<br><br>你说的这个问题我机器上有记录,但现在没有,如果你不着急,我过两天写给你<br><br><br>注册表的你声明一个register类的变量,对其赋值就可以了
 
写注册表我知道了,可是要把当前的文件复制到指定文件夹怎么写代码啊?比如我要把我现在运行的.exe文件复制到c:/winnt/system32/*.exe只要我执行这个文件就自动复制到哪个目录怎么写?
 
有没有关注册表的控件?支持D6,D7的!
 
写到这个下面<br>HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Run<br>或<br>HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/RunServices<br>记得把完整的路径写上<br>
 
to sunroll,<br>不是这个意思啊,我是指把我的执行文件拷贝到另外路径,写注册表已经会了啊。
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
864
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部