本帖最后由 uvloss 于 2011-10-7 10:59 编辑
峪飞鹰 发表于 2011-10-7 09:20
没有实验,不是很清楚结果。不过凭自己的判断,CreateProcess的时候,等于是加载PE文件进内存的操作,实时 ...
方才去Visual Studio的MSDN帮助里面查看了下这个API,具体函数声明及解释如下(只部分截取的有关的第一个参数的使用说明):
BOOL WINAPI CreateProcess(
__in LPCTSTR lpApplicationName,
__in_out LPTSTR lpCommandLine,
__in LPSECURITY_ATTRIBUTES lpProcessAttributes,
__in LPSECURITY_ATTRIBUTES lpThreadAttributes,
__in BOOL bInheritHandles,
__in DWORD dwCreationFlags,
__in LPVOID lpEnvironment,
__in LPCTSTR lpCurrentDirectory,
__in LPSTARTUPINFO lpStartupInfo,
__out LPPROCESS_INFORMATION lpProcessInformation
);
Parameters
lpApplicationName
The name of the module to be executed. This module can be a Windows-based application. It can be some other type of module (for example, MS-DOS or OS/2) if the appropriate subsystem is available on the local computer.
The string can specify the full path and file name of the module to execute or it can specify a partial name. In the case of a partial name, the function uses the current drive and current directory to complete the specification. The function will not use the search path. If the file name does not contain an extension, .exe is assumed. Therefore, if the file name extension is .com, this parameter must include the .com extension.
..........
If the executable module is a 16-bit application, lpApplicationName should be NULL, and the string pointed to by lpCommandLine should specify the executable module as well as its arguments.
To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the name of the batch file.
重点注意红字部分,第一处红字说明载入内存的模块可以是windows应用程序,也可以是dos程序或OS/2程序(雾~)。第二处红字说明如果所给的路径没有给定文件类型,则默认当做EXE文件来处理,而如果给定的文件属于.com文件,则其必须包含.com扩展名。
然后我又用Visual Studio实际测试了下,如果将其他类型的文件去掉扩展名(我用的pdf)用CreateProcess执行,结果会运行失败,错误代码153,貌似是将整个文件当做exe文件来执行的,所以最终打开失败,而如果把普通的exe文件去掉扩展名用CreateProcess执行,正如上面说的,系统将其默认当做exe来执行。
一会儿出去有点事,这个函数先测试到这儿吧,如果大家有兴趣不妨进一步测试。
|