delphi怎样可以读取注册表中的信息,进行注册表操作??我做的delphi程序应该算是绿色的吧,不需要写注册表就可以了,但是要求制作成为不安装不能够使用的形式,怎么办?大家多多提高见,谢谢~

解决方案 »

  1.   

    看帮助TRegistry的使用。上面例子也有。
      

  2.   

    在你安装程序里,例如installshiled中加一个安装注册值,你在你的工程文件当中进行信息读取,读取示例如下:
    function Read_Registry : string ;
    const SECTION = 'Wp';
    var FIniFile: TRegIniFile;
    begin
      FIniFile := TRegIniFile.Create('Software');
      Result := FIniFile.ReadString(SECTION, 'ResInOut', '');
    end;
    该函数读取是
    HKEY_CURRENT_USER\software\wp\
    下'ResInOut'的值
      

  3.   

    把应用软件加上30天的试用期 
    unit regApp; interface uses Windows,SysUtils,Registry,forms, Dialogs; type 
    Tlogin = class 
    private 
    public 
    constructor Create; virtual; 
    procedure CheckLogin; 
    end; 
    implementation constructor Tlogin.Create; 
    begin 
    inherited Create; 
    end; procedure Tlogin.CheckLogin; 
    var 
    Reg_id: TDateTime; 
    RegisterTemp: TRegistry; 
    InputStr, Get_id: string; 
    Reg_tag, ClickDok: Boolean; 
    Allow: Integer; 
    begin 
    Allow := 30; //试用期为30天 
    Reg_tag := False; //软件是否到注册期 
    registerTemp := TRegistry.Create; //准备使用注册表 
    with registerTemp do 
    begin 
    RootKey := HKEY_LOCAL_MACHINE; //存放 
    if OpenKey(''Software\Microsoft\Windows\CurrentSowft\tag'', True) then // 建一目录,存放标志值 
    begin 
    if ValueExists(''DateTag'') then begin //用DateTag的值作为标志 
    Reg_id := ReadDate(''DateTag''); //读出标志值 
    if (Reg_id <> 0) and (Now - Reg_id > Allow) then //允许使用的时间到 
    Reg_tag := True; 
    end 
    else 
    WriteDateTime(''DateTag'', Now); //建立标志,并置初始标志值。 
    end; 
    if Reg_tag then begin //要求用户输入注册码 
    ClickDok := InputQuery(''您使用的是非注册软件,请输入注册码:'', '' '', inputstr); 
    if ClickDok then begin 
    Get_id := IntToStr(2222); //注册码2 
    if Get_id = InputStr then begin 
    WriteDateTime(''DateTag'', 0); //将标志值置为0,即已注册。 
    CloseKey; 
    Free; 
    end 
    else begin //若输入的注册码错误 
    Application.MessageBox(''注册码错误!请与作者联系!'', ''警告框'', mb_ok); 
    CloseKey; 
    Free; 
    Application.Terminate; 
    end; 
    end 
    else begin //若用户不输入注册码 
    Application.MessageBox(''请与作者联系,使用注册软件!'', ''警告框'', mb_ok); 
    CloseKey; 
    Free; 
    Application.Terminate; 
    end; 
    end; 
    end; 
    end; end. 
      

  4.   

    The following example retrieves a value from a registry entry.uses Registry; 
    function GetRegistryValue: string;
    var
      Registry: TRegistry;
      S: string;
    begin
      Registry:=TRegistry.Create;  Registry.RootKey:=HKEY_LOCAL_MACHINE;
      {False because we do not want to create it if it doesn抰 exist}
      Registry.OpenKey('MYKEY',False); 
      Result :=Registry.ReadString('VALUE1');  Registry.Free;
    end;The following example shows how to tell Windows to relaunch your application when Windows starts up if it was running when the system shut down. When Windows starts up, it launches each application listed in the RunOnce key and then deletes the entry for that application.  Therefore, you do not need to remove the entry written here.procedure TForm1.WMEndSession(var Message: TWMEndSession);
    var
      Reg: TRegistry;
    begin
      Reg := TRegistry.Create;
      try
        Reg.RootKey := HKEY_CURRENT_USER;
        if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\RunOnce', True) then
        begin
          Reg.WriteString('MyApp','"' + ParamStr(0) + '"');
          Reg.CloseKey;
        end;
      finally
        Reg.Free;
        inherited;
      end;end;
    In order for this method to be called, it must be declared in your main form class as follows:private  procedure WMEndSession(var Msg:TWMEndSession); message WM_ENDSESSION;