100分寻求答案!把指定的目录下文件打包成执行文件,点击后,自动运行默认的文件,怎么处理?谢谢!!!急!!!!!

cdsun 2006-05-25 09:34:03
各位高手:
比如:有一个文件夹在我软件的安装目录下,此目录下有相关文件a.exe,b.txt,c,d,e......。

现在,我想通过一种方法(就是我想请教的)生成一个文件,设为aaa.exe,我双击aaa.exe,然后不用我干预(不用双击a.exe),自动执行a.exe。 请教怎么处理?谢谢各位高手!

...全文
258 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
cdsun 2006-05-31
  • 打赏
  • 举报
回复
我没用会上面的代码
谁能给一点点说明阿
cdsun 2006-05-26
  • 打赏
  • 举报
回复
好的
谢谢啦。
postren 2006-05-26
  • 打赏
  • 举报
回复
我怎么可以连续回复这么多次啊?
postren 2006-05-26
  • 打赏
  • 举报
回复
这个工程是解压用的,压缩打包也差不多,研究研究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;
postren 2006-05-26
  • 打赏
  • 举报
回复
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;
postren 2006-05-26
  • 打赏
  • 举报
回复
其中把rar压缩包文件放到了{$R Dll.res}了

这个工程是自动安装Sybase ODBC Driver的

你参考一下
postren 2006-05-26
  • 打赏
  • 举报
回复
//单元文件
unit SybaseODBC;

interface

uses
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}

implementation

class 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.
postren 2006-05-26
  • 打赏
  • 举报
回复
//工程文件
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.
postren 2006-05-26
  • 打赏
  • 举报
回复
我有段代码是把文件添加到res中的

帮找找
cdsun 2006-05-26
  • 打赏
  • 举报
回复
postren(小虫)能不能帮个忙给一个demo
用delphi控制rar能达到我的这个效果的
cdsun 2006-05-26
  • 打赏
  • 举报
回复
postren(小虫)

rar能实现我也知道

可是不知道具体怎么用delphi来控制他
cdsun 2006-05-26
  • 打赏
  • 举报
回复
刚才打错了不是不容合成一个包
我的意思是不要把所有的文件融合成一个文件
postren 2006-05-26
  • 打赏
  • 举报
回复
WinRar本身就支持的
bladestar 2006-05-26
  • 打赏
  • 举报
回复
我这样的要求是在打包后,文件还是一个一个的单独的,而不是把所有的文件融合成一个包
====================

如果你把文件当作二进制流写进取,必然是“一个包”。但是你可以确定每个文件的位置,再读出来

我对你的需求有点迷惑
cdsun 2006-05-26
  • 打赏
  • 举报
回复
我说得还不够清楚啊?

我不知道你想让我怎么说
bladestar 2006-05-26
  • 打赏
  • 举报
回复
说下你的大致思路,delphi我不熟
cdsun 2006-05-26
  • 打赏
  • 举报
回复
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;
cdsun 2006-05-26
  • 打赏
  • 举报
回复
如何分解?>

汉字我也会打阿大哥

我的合并代码如下
cdsun 2006-05-26
  • 打赏
  • 举报
回复
还有没有其他朋友帮忙的
bladestar 2006-05-25
  • 打赏
  • 举报
回复
合并后分解文件
加载更多回复(3)

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧