createprocess重启程序,CreateProcess无法成功启动我的进程,但双击正确运行exe

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);

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??????

解决方案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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值