我想为我的项目打开一个外部程序。好的。它是这样的文件夹:
... 的 Externalapp.exe
但是对于 Externalapp.exe 工作,它需要一个名为 key.lua 的文件,用户无法看到(出于安全原因)< / em>的
所以我想我在 Externalapp.exe 的动态调用中包含此文件,让他认为 key.lua 就在你身边。
有可能吗?
答案 0 :(得分:0)
首先谈谈安全问题:
正如其他人已经在评论中提到的,存储有关LUA文件中的安全性的任何数据都是一个糟糕的主意。为什么? LUA文件是文本文件,因此任何用户都可以看到它的内容。现在你可以尝试通过将它放入一些不那么明显的文件夹来隐藏这个文件,但是仍然存在用户可能以某种方式偶然发现它的风险。
如果您可以更改ExternalApp Campaast,则可以加载加密的LUA文件并加密LUA文件。
现在回答你的问题:
通过将工作区设置为与ExternalApp位置不同,可以说服您的ExternalApp加载与ExternalApp不在同一目录中的LUA文件。
这是一个使用ShellExecute和ShellExecuteEx API调用的Delphi代码示例。
procedure TForm2.Button1Click(Sender: TObject);
var SEInfo: TShellExecuteInfo;
ExitCode: DWORD;
begin
//Using ShellExecute
ShellExecute(Handle,'open','C:\ExternalApp.exe',nil,'D:\',SW_SHOWNORMAL);
//Using ShellExecuteEx
FillChar(SEInfo, SizeOf(SEInfo), 0);
SEInfo.cbSize := SizeOf(TShellExecuteInfo);
SEInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
SEInfo.Wnd := Application.Handle;
SEInfo.lpFile := PChar('C:\ExternalApp.exe');
SEInfo.lpDirectory := PCHAR('D:\');
SEInfo.nShow := SW_SHOWNORMAL;
if ShellExecuteEx(@SEInfo) then
begin
repeat
Application.ProcessMessages;
GetExitCodeProcess(SEInfo.hProcess, ExitCode) ;
until (ExitCode <> STILL_ACTIVE) or Application.Terminated;
ShowMessage('External application terminated') ;
end
else
ShowMessage('Error starting External application!') ;
end;
注意:仅当您的ExternalApp尝试使用GetCurrentDirectory或GetWorkDirectory cals来查找LUA文件以获取LUA文件的路径位置时,此方法才有效。 但是,如果您的ExternalApp通过提取其可执行文件的路径位置来获取此路径,则它将无法工作。