function SetAutoRun(FName, sKey_Name : String) : Boolean;
const
sKey_Run = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run';
var
RegKey: HKEY;
begin
Result := False;
if RegOpenKey(HKEY_LOCAL_MACHINE, sKEY_Run, RegKey) = ERROR_SUCCESS then
try
if FName = '' then
Result := RegDeleteValue(RegKey, sKey_Name) = ERROR_SUCCESS
else
Result := RegSetValueEx(RegKey, sKey_Name, 0, REG_SZ, PChar(FName), Length(FName)) = ERROR_SUCCESS;
finally
RegCloseKey(RegKey);
end;
end;调用为SetAutoRun(Application.FileName, '我的程序');
const
sKey_Run = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run';
var
RegKey: HKEY;
begin
Result := False;
if RegOpenKey(HKEY_LOCAL_MACHINE, sKEY_Run, RegKey) = ERROR_SUCCESS then
try
if FName = '' then
Result := RegDeleteValue(RegKey, sKey_Name) = ERROR_SUCCESS
else
Result := RegSetValueEx(RegKey, sKey_Name, 0, REG_SZ, PChar(FName), Length(FName)) = ERROR_SUCCESS;
finally
RegCloseKey(RegKey);
end;
end;调用为SetAutoRun(Application.FileName, '我的程序');
解决方案 »
- 怎样实现DBGrideh的行循环
- 在ServerSocket中如何区分客户端,向各指定的客户连接分别发送信息?
- 一个简单的问题?
- DBGrid1怎样按回车代替TAB键
- 请问,自动创建的窗体(非主窗体),它的Parent是什么呢?
- TIdudpServer使用中出现的疑问,望各位大虾帮忙?
- [Fatal Error] Project1.dpr(1): File not found: 'System.pas' 怎么办??????
- 如何根据进程id取得程序名?
- 闲来无事,用DELPHI做了个浏览器,下载有分
- 可以直接从数据库中读写variant类型的数据吗?在线等候
- 如何去掉sql登录口令认证
- 怎样得到LISTVIEW中SUBITEM的CAPTION值?
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
procedure TForm1.FormCreate(Sender: TObject);
var
R:TRegistry;
begin
R:=TRegistry.Create;
R.RootKey:=HKEY_LOCAL_MACHINE;
R.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run',True);
R.WriteString('MyApp',Application.ExeName);
R.CloseKey;
R.Free;
end;
如果想程序在后台运行可以在窗体创建过程中写上
Application.ShowMainForm:=False;就可以了