关闭

进程方式执行CMD命令及使用CMD命令一次创建多级录

标签: cmdinheritancecommandstructurethreadmodule
1186人阅读 评论(0) 收藏 举报
分类:
void exceCmd(LPCTSTR cmdLines)
{
	STARTUPINFO si;
	PROCESS_INFORMATION pi;

	ZeroMemory( &si, sizeof(si) );
	si.cb = sizeof(STARTUPINFO);
	ZeroMemory( &pi, sizeof(pi) );

	//这两句一定要,否则会显示出黑框框.
	si.wShowWindow = SW_HIDE;
	si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;

	TCHAR cmdBuf[0x100]={0};
	_stprintf_s(cmdBuf,TEXT("cmd /k %s"),cmdLines);
	// Start the child process. 
	if( !CreateProcess( NULL,   // No module name (use command line)
		cmdBuf,        // Command line
		NULL,           // Process handle not inheritable
		NULL,           // Thread handle not inheritable
		FALSE,          // Set handle inheritance to FALSE
		0,              // No creation flags
		NULL,           // Use parent's environment block
		NULL,           // Use parent's starting directory 
		&si,            // Pointer to STARTUPINFO structure
		&pi )           // Pointer to PROCESS_INFORMATION structure
		) 
	{
		OutputDebugString(TEXT("失败"));
		return;
	}

	// Wait until child process exits.
	WaitForSingleObject( pi.hProcess, INFINITE );
	// Close process and thread handles. 
	CloseHandle( pi.hProcess );
	CloseHandle( pi.hThread );
}
BOOL makeDir(LPCTSTR strPath)
{
	CString Str=strPath;
	if(Str.GetLength()>3)
	{
		if( Str.ReverseFind('.') > 0 )
		{
			int Index = Str.ReverseFind('\\');
			Str = Str.Left(Index);
		}
		Str = TEXT("md ")+Str;
		exceCmd(Str);
		return TRUE;
	}
	return FALSE;
}


1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:112643次
    • 积分:1045
    • 等级:
    • 排名:千里之外
    • 原创:13篇
    • 转载:4篇
    • 译文:0篇
    • 评论:46条
    文章分类
    最新评论