使用创建流程功能创建另一个进程 [英] Create another Process using Create PRocess Function
本文介绍了使用创建流程功能创建另一个进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//#include "stdafx.h"
#include <windows.h>
#include <direct.h>
#include <string.h>
#include <tchar.h>
#include <strsafe.h>
void RunTest(TCHAR *AppName, TCHAR *CmdLine)
{
// Appname="C:\\Windows\\System32\\cscipt.exe";
//CmdLine="E:\\mof.vbs";
wprintf(L"\nTest Running...\n");
wprintf(L" AppName: %s\n", AppName);
wprintf(L" CmdLine: %s\n", CmdLine);
PROCESS_INFORMATION processInformation;
STARTUPINFO startupInfo;
memset(&processInformation, 0, sizeof(processInformation));
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
BOOL result;
TCHAR tempCmdLine[MAX_PATH * 2]; //Needed since CreateProcessW may change the contents of CmdLine
if (CmdLine != NULL)
{
//wprintf(L"ERROR: CreateProcess failed!");
_tcscpy_s(tempCmdLine, MAX_PATH *2, CmdLine);
result = ::CreateProcess(AppName, tempCmdLine, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &startupInfo, &processInformation);
}
else
{
result = ::CreateProcess(AppName, CmdLine, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &startupInfo, &processInformation);
}
if (result == 0)
{
wprintf(L"ERROR: CreateProcess failed!");
}
else
{
WaitForSingleObject( processInformation.hProcess, INFINITE );
CloseHandle( processInformation.hProcess );
CloseHandle( processInformation.hThread );
}
}
int _tmain(int argc, TCHAR* argv[])
{
//Assumes ParamTest.exe is in the current working directory
RunTest(L"C:\\Windows\\System32\\cscipt.exe", L"E:\\mof.vbs");
return 0;
}
错误:CreateProcess失败!"它会在运行时引发此类错误
帮助我了解如何使用createprocess
函数创建进程.
"ERROR: CreateProcess failed!" It raises such kind of error at run time
Help me out with how to create a process using createprocess
function.
推荐答案
我认为它是"cscript.exe",而不是"cscipt.exe" .试试吧;)
I think it''s "cscript.exe", not "cscipt.exe". Try that ;)
这篇关于使用创建流程功能创建另一个进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文