//问题: 把文件以流的方式读出来,接着运行流文件(50分)

A

abencat

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; strmSource:TMemoryStream;<br>begin<br>&nbsp; //问题: 把文件以流的方式读出来,接着运行流文件<br><br>&nbsp; //先读<br>&nbsp; strmSource:=TMemoryStream.Create;<br>&nbsp; strmSource.LoadFromFile('C:/a.exe');<br><br>&nbsp; //下面如何直接运行文件流<br>&nbsp; //.......<br><br>&nbsp; //释放<br>&nbsp; strmSource.free;<br><br>end;<br>
 
如何用CreateProcess运行
 
直接运行 winexec('C:/a.exe',0) 即可<br><br>createprocess<br><br>procedure mycreateprocess; <br>var <br>&nbsp; &nbsp; &nbsp; &nbsp; t:TStartupInfo; <br>&nbsp; &nbsp; &nbsp; &nbsp; s:TProcessInformation; <br>&nbsp; &nbsp; &nbsp; &nbsp; {$IFDEF Win32} <br>&nbsp; &nbsp; &nbsp; &nbsp; flag:boolean; <br>&nbsp; &nbsp; &nbsp; &nbsp; {$ENDIF} <br>&nbsp; &nbsp; &nbsp; &nbsp; {$IFDEF Win16} <br>&nbsp; &nbsp; &nbsp; &nbsp; flag1:integer; <br>&nbsp; &nbsp; &nbsp; &nbsp; {$ENDIF} <br>begin <br>&nbsp; &nbsp; &nbsp; &nbsp; t.cb:=Sizeof(STARTUPINFO); <br>&nbsp; &nbsp; &nbsp; &nbsp; //Specifies the size,in bytes,of the structure. <br><br>&nbsp; &nbsp; &nbsp; &nbsp; t.dwFlags:=STARTF_USESHOWWINDOW; <br>&nbsp; &nbsp; &nbsp; &nbsp; //If this value is not specified,the wShowWindow member is ignored. <br><br>&nbsp; &nbsp; &nbsp; &nbsp; t.wShowWindow:=SW_NORMAL; <br>&nbsp; &nbsp; &nbsp; &nbsp; //Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time. <br><br>&nbsp; &nbsp; &nbsp; &nbsp; t.cbReserved2:=0; <br>&nbsp; &nbsp; &nbsp; &nbsp; //Reserved;must be zero. <br><br>&nbsp; &nbsp; &nbsp; &nbsp; t.lpReserved:=nil; <br>&nbsp; &nbsp; &nbsp; &nbsp; //Reserved.Set this member to nil before passing the structure to CreateProcess. <br><br>&nbsp; &nbsp; &nbsp; &nbsp; t.lpReserved2:=nil; <br>&nbsp; &nbsp; &nbsp; &nbsp; //Reserved;must be nil. <br><br>&nbsp; &nbsp; &nbsp; &nbsp; t.lpDesktop:=nil; <br>&nbsp; &nbsp; &nbsp; &nbsp; //Windows NT only: Points to a zero-terminated string that specifies either the name of the desktop only or the name of both the window station and desktop for this process. <br>&nbsp; &nbsp; &nbsp; &nbsp; //A backslash in the string pointed to by lpDesktop indicates that the string includes both desktop and window station names. <br>&nbsp; &nbsp; &nbsp; &nbsp; //Otherwise, the lpDesktop string is interpreted as a desktop name. <br>&nbsp; &nbsp; &nbsp; &nbsp; //If lpDesktop is NULL, the new process inherits the window station and desktop of its parent process. <br><br>&nbsp; &nbsp; &nbsp; &nbsp; t.lpTitle:=nil; <br>&nbsp; &nbsp; &nbsp; &nbsp; //For console processes, <br>&nbsp; &nbsp; &nbsp; &nbsp; //this is the title displayed in the title bar if a new console window is created. <br>&nbsp; &nbsp; &nbsp; &nbsp; //If NULL, the name of the executable file is used as the window title instead. <br>&nbsp; &nbsp; &nbsp; &nbsp; //This parameter must be NULL for GUI or console processes that do not create a new console window. <br><br>&nbsp; &nbsp; &nbsp; &nbsp; {$IFDEF Win32} <br>&nbsp; &nbsp; &nbsp; &nbsp; if(classify='0')then <br>&nbsp; &nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flag:=CreateProcess(Pchar(commandline),nil,nil,nil,false,NORMAL_PRIORITY_CLASS,nil,nil,t,s); <br>&nbsp; &nbsp; &nbsp; &nbsp; end <br>&nbsp; &nbsp; &nbsp; &nbsp; else begin <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flag:=CreateProcess(nil,Pchar(commandline),nil,nil,false,NORMAL_PRIORITY_CLASS,nil,nil,t,s); <br>&nbsp; &nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; &nbsp; &nbsp; {$ENDIF} <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; {$IFDEF Win16} <br>&nbsp; &nbsp; &nbsp; &nbsp; flag1:=WinExec(Pchar(commandline),SW_MAXIMIZE); <br>&nbsp; &nbsp; &nbsp; &nbsp; {$ENDIF} <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; {$IFDEF Win32} <br>&nbsp; &nbsp; &nbsp; &nbsp; if not(flag)then <br>&nbsp; &nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; savelog('CreateProcess error!'); <br>&nbsp; &nbsp; &nbsp; &nbsp; end <br>&nbsp; &nbsp; &nbsp; &nbsp; else begin <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; savelog('CreateProcess success!'); <br>&nbsp; &nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; &nbsp; &nbsp; {$ENDIF} <br>end; <br><br><br><br>createprocess中的第一个参数可用来执行application,第二个参数可用来执行命令行(如net stop w3svc) <br>不建义使用winexec,它是16位的,尽因为向后兼容才保留!! <br>
 
这类问题在这里是找不到答案的,n年前就有人提过了![:(]
 
希望能得到高手的指点
 
不好意思,看错问题了<br><br>这个问题我也想知道,关注!<br>好像aspack就是用的这个技术,把其他文件压缩后加入本身,运行时取出exe直接在内存中运行<br>没有存为临时文件再运行
 
名师在那里? 请你指点迷津
 
好问题!关注。
 
怎么没有人来谈谈呀?
 
http://www.delphijs.net
 
多人接受答案了。
 
abencat兄,你搞定了吗?
 
顶部