CreateProcess无法成功启动我的进程,但双击正确运行exe [英] CreateProcess can not successfully start my process but the exe is running properly by double clicking

查看:1410
本文介绍了CreateProcess无法成功启动我的进程,但双击正确运行exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过CreateProcess方法成功运行两个exe。这两个exe中的每一个在启动期间都会读取一些文件,注册表和数据库。我已经测试了相同的代码来运行系统计算器并且工作正常。



当我尝试通过CreateProcess方法运行这些应用程序时,第一个应用程序正在运行启动后自动关闭,第二个无法打开xx.dat文件,无法读取注册表和数据库。请参阅以下代码。



I can't run two exe successfully by CreateProcess method. Each of those two exe's reads some files, registry and database during start up. I have tested the same code to run the system calculator and it is working fine.

When I am trying to run those applications by CreateProcess method, the first application is getting closed automatically after start up and the second one cannot open xx.dat file and failed to read registry and data base. Please see the following code.

PROCESS_INFORMATION processinfo;
STARTUPINFO startUpInfo;
ZeroMemory(&processinfo, sizeof(processinfo));
ZeroMemory(&startUpInfo, sizeof(startUpInfo));
startUpInfo.cb = sizeof(startupInfo);

BOOL bSuccess = CreateProcess(csAppName, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startUpInfo, &processinfo);





我总是将bSuccess改为TRUE。

计算器成功运行此代码但是那些两个应用程序没有。

我也尝试过使用runas参数的ShellExecute()和ShellExecuteEx()方法,但结果是一样的。

可以任何人帮助我??????



I am getting bSuccess as TRUE always.
Calculator is successfully running with this code but those two applications not.
Also I have tried with "ShellExecute()" and "ShellExecuteEx()" methods with "runas" parameter, but result is the same.
Can anyone help me??????

推荐答案

您已将 lpCurrentDirectory 参数指定为NULL,因此可执行文件的默认运行目录是调用进程的当前目录。

如果要读取的文件位于另一个目录中,则代码将失败。此外,如果找不到组件,它将失败(请参阅 [ ^ ])。因为函数在进程初始化之前返回,如果无法找到所需的DLL,或者无法初始化,则进程终止。

您可以提供要打开的文件的完整路径,或者您必须提供运行应用程序的当前目录。
You have assigned to NULL the lpCurrentDirectory parameter, so the default running directory of your executable is the current directory of the calling process.
If the files to read are in another directory the code will fail. Moreover it will fail if a component is not found (see[^]). Because the function returns before the process has finished initialization if a required DLL cannot be located, or fails to initialize, the process is terminated.
You can supply the full path for files to open or you have to supply the current directory from where to run the application.


这篇关于CreateProcess无法成功启动我的进程,但双击正确运行exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆