各位高手:
    比如:有一个文件夹在我软件的安装目录下,此目录下有相关文件a.exe,b.txt,c,d,e......。    现在,我想通过一种方法(就是我想请教的)生成一个文件,设为aaa.exe,我双击aaa.exe,然后不用我干预(不用双击a.exe),自动执行a.exe。 请教怎么处理?谢谢各位高手!

解决方案 »

  1.   

    procedure TForm1.AddFile(FileName:String);
    var
      mStream1, mStream2: TMemoryStream;
      i: integer;
    begin
      Form1.ListBox1.ItemIndex := Form1.ListBox1.Items.Add('合并开始...');
      i := 1;
      mStream1 := TMemoryStream.Create;
      mStream2 := TMemoryStream.Create;
      Form1.ListBox1.ItemIndex := Form1.ListBox1.Items.Add('为合并开始分配内存...');
      mStream1.loadfromfile(FileName + '1');
      Form1.ListBox1.ItemIndex := Form1.ListBox1.Items.Add('为合并开始寻找相关文件...');
      while i < 10 do
      begin
        Form1.ListBox1.ItemIndex := Form1.ListBox1.Items.Add('为合并开始寻找到第'+inttostr(i)+'个相关文件...');
        mStream2.loadfromfile(FileName + IntToStr(i + 1));
        mStream1.seek(mStream1.size, soFromBeginning);
        mStream1.copyfrom(mStream2, mStream2.size);
        mStream2.clear;
        i := i + 1;
      end;
      mStream2.free;
      Form1.ListBox1.ItemIndex := Form1.ListBox1.Items.Add('释放合并文件使用的内存...');
      mStream1.SaveToFile('aa.txt');
      Form1.ListBox1.ItemIndex := Form1.ListBox1.Items.Add('为合并后的文件改名...');
      mStream1.free;
      Form1.ListBox1.ItemIndex := Form1.ListBox1.Items.Add('释放主文件申请的内存...');
      //删除临时文件  Form1.ListBox1.ItemIndex := Form1.ListBox1.Items.Add('合并成功!');
    end;
      

  2.   

    说下你的大致思路,delphi我不熟
      

  3.   

    postren(小虫)rar能实现我也知道可是不知道具体怎么用delphi来控制他
      

  4.   

    postren(小虫)能不能帮个忙给一个demo
    用delphi控制rar能达到我的这个效果的
      

  5.   

    我有段代码是把文件添加到res中的帮找找
      

  6.   

    //工程文件
    program SybaseDriver;uses
      Forms,
      Windows,
      SybaseODBC in 'SybaseODBC.pas';{$R *.res}begin
      if TSybaseODBC.RegSybaseOdbcDriver then
      begin
        MessageBox(Application.Handle, '安装Sybase ODBC Driver ver4.20.00.15成功',
          PChar('Sybase ODBC Driver'), MB_OK or MB_ICONINFORMATION);
      end else
      begin
        MessageBox(Application.Handle, '安装Sybase ODBC Driver ver4.20.00.15失败',
          PChar('Sybase ODBC Driver'), MB_OK or MB_ICONWARNING);
      end;
    end.
      

  7.   

    //单元文件
    unit SybaseODBC;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ShellAPI, Registry;type
      TSybaseODBC = class
      private
        FPath: string;
        FRarName: string;
        FResName: string;
        function RegOdbc: Boolean;
        function GetWindowsDir: string;
        procedure UnPackRarFile;
        function IsUnRegSybaseDriver: Boolean;
        function UnPackedToPath(const Path: string): Boolean;
        function UnPackedToHere: Boolean;
      public
        constructor Create(const Path: string); overload;
        constructor Create; overload;
        destructor Destroy;
        class function RegSybaseOdbcDriver: Boolean;
        { Public declarations }
      end;  {$R Dll.res}implementationclass function TSybaseODBC.RegSybaseOdbcDriver: Boolean;
    var
      F: TSybaseODBC;
    begin
      Result := False;
      F := TSybaseODBC.Create;
      Result := True;
      F.Free;
    end;{ TSybaseODBC }constructor TSybaseODBC.Create(const Path: string);
    begin
      FPath := Path;
      if Trim(Path) = '' then FPath := GetWindowsDir;
      if IsUnRegSybaseDriver then
      begin
        Self.UnPackRarFile;
        Self.UnPackedToHere;
        if not Self.RegOdbc then
          raise Exception.Create('Can''t reg the Sybase ODBC Driver!');
      end;
    end;constructor TSybaseODBC.Create;
    var
      Path: string;
    begin
      Path := GetWindowsDir;
      Create(Path);
    end;destructor TSybaseODBC.Destroy;
    begin
      DeleteFile(FRarName);
      DeleteFile(FResName);
      inherited Destroy;
    end;function TSybaseODBC.GetWindowsDir: string;
    var
      WDir: array [0..255] of Char;
    begin
      GetSystemDirectory(WDir, SizeOf(WDir));
      Result := StrPas(WDir) + '\SybaseDriver12.5';
      if not DirectoryExists(Result) then
      begin
        MkDir(Result);
      end;
    end;function TSybaseODBC.IsUnRegSybaseDriver: Boolean;
    var
      Reg: TRegistry;
    begin
      Result := True;
      Reg := TRegistry.Create;
      try
        Reg.RootKey := HKEY_LOCAL_MACHINE;
        if Reg.KeyExists('\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers') then
        begin
          Reg.OpenKey('\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers',True);
          if Reg.ValueExists('Sybase ASE ODBC Driver for My') then
          begin
            if Reg.ReadString('Sybase ASE ODBC Driver for My') = 'Installed' then
            begin
              Result := False;
            end;
          end;
          Reg.CloseKey;
        end;
      finally
        Reg.Free;
      end;
    end;function TSybaseODBC.RegOdbc: Boolean;
    var
      Reg: TRegistry;
    begin
      Result := False;
      Reg := TRegistry.Create;
      try
        Reg.RootKey := HKEY_LOCAL_MACHINE;
        if Reg.KeyExists('\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers') then
        begin
          Reg.OpenKey('\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers',True);
          if Reg.ValueExists('Sybase ASE ODBC Driver for My') then
          begin
            if Reg.ReadString('Sybase ASE ODBC Driver for My') = 'Installed' then
            begin
              Result := True;
            end else
            begin
              Reg.WriteString('Sybase ASE ODBC Driver for My', 'Installed');
              Reg.CloseKey;
              if Reg.OpenKey('\SOFTWARE\ODBC\ODBCINST.INI\Sybase ASE ODBC Driver for My', True) then
              begin
                Reg.WriteString('AltDefaults', '1');
                Reg.WriteString('APILevel', '1');
                Reg.WriteString('ConnectionFunctions', 'YYY');
                Reg.WriteString('CPTimeout', '60');
                Reg.WriteString('Driver', FPath + '\SYODASE.DLL');
                Reg.WriteString('DriverODBCVer', '04.10');
                Reg.WriteString('FileUsage', '0');
                Reg.WriteString('Setup', FPath + '\SYODASES.DLL');
                Reg.WriteString('SQLLevel', '0');
                Reg.WriteString('HelpRootDirectory', FPath + '\Help');
                Reg.CloseKey;
                Result := True;            
              end else
              begin
                Result := False;
                raise Exception.Create('Can''t operate the Registry!');
              end;
            end;
          end else
          begin
            Reg.WriteString('Sybase ASE ODBC Driver for BCSPIF', 'Installed');
            Reg.CloseKey;
            if Reg.OpenKey('\SOFTWARE\ODBC\ODBCINST.INI\Sybase ASE ODBC Driver for My', True) then
            begin
              Reg.WriteString('AltDefaults', '1');
              Reg.WriteString('APILevel', '1');
              Reg.WriteString('ConnectionFunctions', 'YYY');
              Reg.WriteString('CPTimeout', '60');
              Reg.WriteString('Driver', FPath + '\SYODASE.DLL');
              Reg.WriteString('DriverODBCVer', '04.10');
              Reg.WriteString('FileUsage', '0');
              Reg.WriteString('Setup', FPath + '\SYODASES.DLL');
              Reg.WriteString('SQLLevel', '0');
              Reg.WriteString('HelpRootDirectory', FPath + '\Help');
              Reg.CloseKey;
              Result := True;
            end else
            begin
              Result := False;
              raise Exception.Create('Can''t operate the Registry!');
            end;
          end;
        end;
      finally
        Reg.Free;
      end;
    end;function WinExecAndWait32(FileName:String; Visibility : integer):integer;
    var 
      zAppName:array[0..512] of char; 
      zCurDir:array[0..255] of char; 
      WorkDir:String; 
      StartupInfo:TStartupInfo; 
      ProcessInfo:TProcessInformation; 
    begin 
      StrPCopy(zAppName,FileName); 
      GetDir(0,WorkDir); 
      StrPCopy(zCurDir,WorkDir); 
      FillChar(StartupInfo,Sizeof(StartupInfo),#0); 
      StartupInfo.cb := Sizeof(StartupInfo);   StartupInfo.dwFlags := STARTF_USESHOWWINDOW; 
      StartupInfo.wShowWindow := Visibility; 
      if not CreateProcess(nil, 
        zAppName,                       { pointer to command line string } 
        nil,                            { pointer to process security attributes } 
        nil,                            { pointer to thread security attributes } 
        false,                          { handle inheritance flag } 
        CREATE_NEW_CONSOLE or           { creation flags } 
        NORMAL_PRIORITY_CLASS, 
        nil,                            { pointer to new environment block } 
        nil,                            { pointer to current directory name } 
        StartupInfo,                    { pointer to STARTUPINFO } 
        ProcessInfo) then Result := -1 { pointer to PROCESS_INF }   else begin
        WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
        GetExitCodeProcess(ProcessInfo.hProcess,LongWord(Result));
      end; 
    end;function TSybaseODBC.UnPackedToHere: Boolean;
    begin
      Result := UnPackedToPath(FPath);
    end;function TSybaseODBC.UnPackedToPath(const Path: string): Boolean;
    var
      S, S2: string;
    begin
      S := '"' + FRarName + '"';
      S2 := ' x -w -o- "' + FResName + '" "' + Path + '"';
      Result := WinExecAndWait32(S + S2, SW_SHOW) = 0;
    end;procedure TSybaseODBC.UnPackRarFile;
    var
      Res: TResourceStream;
    begin
      FRarName := FPath + '\Rar.exe';
      FResName := FPath + '\ODBCSYBASE.tmp';
      try
        Res := TResourceStream.Create(hInstance, 'RAR', 'RAR');
        try
          Res.Position := 0;
          Res.SaveToFile(FRarName);
        except
          raise Exception.Create('Cann''t create Rar File! Please check the disk...');
        end;
      finally
        Res.Free;
      end;
      try
        Res := TResourceStream.Create(hInstance, 'ODBCSYBASE', 'DLL');
        try
          Res.Position := 0;
          Res.SaveToFile(FResName);
        except
          raise Exception.Create('Cann''t create ODBCSYBASE File! Please check the disk...');
        end;
      finally
        Res.Free;
      end;
    end;end.
      

  8.   

    其中把rar压缩包文件放到了{$R Dll.res}了这个工程是自动安装Sybase ODBC Driver的你参考一下
      

  9.   

    procedure TSybaseODBC.UnPackRarFile;
    var
      Res: TResourceStream;
    begin
      FRarName := FPath + '\Rar.exe';
      FResName := FPath + '\ODBCSYBASE.tmp';
      try
        Res := TResourceStream.Create(hInstance, 'RAR', 'RAR'); //这里是Rar.exe
        try
          Res.Position := 0;
          Res.SaveToFile(FRarName);
        except
          raise Exception.Create('Cann''t create Rar File! Please check the disk...');
        end;
      finally
        Res.Free;
      end;
      try
        Res := TResourceStream.Create(hInstance, 'ODBCSYBASE', 'DLL'); //这里是一个Rar压缩包
        try
          Res.Position := 0;
          Res.SaveToFile(FResName);
        except
          raise Exception.Create('Cann''t create ODBCSYBASE File! Please check the disk...');
        end;
      finally
        Res.Free;
      end;
    end;
      

  10.   

    这个工程是解压用的,压缩打包也差不多,研究研究Rar的命令行参数就能搞定可以修改下面这个函数 把压缩需要的参数放进去,就能搞定
    function TSybaseODBC.UnPackedToPath(const Path: string): Boolean;
    var
      S, S2: string;
    begin
      S := '"' + FRarName + '"';
      S2 := ' x -w -o- "' + FResName + '" "' + Path + '"';
      Result := WinExecAndWait32(S + S2, SW_SHOW) = 0;
    end;