procedure TMainForm.SetAutoRun(ok: boolean); var Reg:TRegistry; //首先定义一个TRegistry类型的变量Reg begin Reg:=TRegistry.Create; try //创建一个新键 Reg.RootKey:=HKEY_LOCAL_MACHINE; //将根键设置为HKEY_LOCAL_MACHINE Reg.OpenKey('Software/Microsoft/Windows/CurrentVersion/Run',true);//打开一个键 if ok then begin Reg.WriteString('SMS服务',ExpandFileName(ParamStr(0))); //在Reg这个键中写入数据名称和数据数值 ShowMessage('注册成功!'); end else begin reg.DeleteValue('SMS服务'); ShowMessage('删除成功!') end; Reg.CloseKey; //关闭键 finally Reg.Free; end; end;