当前位置: 首页 > news >正文

VC常用代码之创建进程

作者:朱金灿

来源:http://blog.csdn.net/clever101

 

           创建进程是编程开发的常用操作。Windows中的创建进程采用API函数CreateProcess实现。下面是一个使用例子:

#include <Windows.h>
#include <string>

int _tmain(int argc, _TCHAR* argv[])
{

	STARTUPINFO si;
	PROCESS_INFORMATION pi;

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

	std::string strCmdLine = "ping www.baidu.com";
 
	// Start the child process. 
	if( !CreateProcess( NULL,   // No module name (use command line)
		(LPSTR)strCmdLine.c_str(),        // 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
		) 
	{
		printf( "CreateProcess failed (%d)\n", GetLastError() );
		return 1;
	}

	// Wait until child process exits.
	WaitForSingleObject( pi.hProcess, INFINITE );

	// Close process and thread handles. 
	CloseHandle( pi.hProcess );
	CloseHandle( pi.hThread );

   getchar();
   return 0;
}

        使用上面的方式创建进程会出现一个控制台界面。要隐藏这个控制台界面,只需要将CreateProcess函数的第六个参数设为CREATE_NO_WINDOW,比如上面对应的代码应改为:

	if( !CreateProcess( NULL,   // No module name (use command line)
		(LPSTR)strCmdLine.c_str(),        // Command line
		NULL,           // Process handle not inheritable
		NULL,           // Thread handle not inheritable
		FALSE,          // Set handle inheritance to FALSE
		CREATE_NO_WINDOW,              // 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
		) 
	{
		printf( "CreateProcess failed (%d)\n", GetLastError() );
		return 1;
	}

转载于:https://www.cnblogs.com/lanzhi/p/6470021.html

相关文章:

  • 第六章 对象作用域与servlet事件监听器
  • JavaScript HTML DOM 事件
  • 3D-HEVC的TAppDecorder
  • Hibenate second-level ehcache
  • JVM垃圾回收日志结构分析
  • MFC用户界面套包BCGControlBar Pro for MFC v24.3正式发布[附下载]
  • 线程的创建
  • Android EditText 多行,滚动条 等
  • C#中两个时间的比较
  • Eclipse导入第三方库或工程时出现红色叹号的解决方法
  • Redis Ltrim 命令
  • android Volley 使用
  • glob 模块
  • 一行代码解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10
  • centos平台openstack spice配置
  • [iOS]Core Data浅析一 -- 启用Core Data
  • 2018以太坊智能合约编程语言solidity的最佳IDEs
  • Angular 响应式表单之下拉框
  • Angular4 模板式表单用法以及验证
  • ES6, React, Redux, Webpack写的一个爬 GitHub 的网页
  • ES学习笔记(12)--Symbol
  • gitlab-ci配置详解(一)
  • java中具有继承关系的类及其对象初始化顺序
  • Spring Security中异常上抛机制及对于转型处理的一些感悟
  • VUE es6技巧写法(持续更新中~~~)
  • Yii源码解读-服务定位器(Service Locator)
  • 案例分享〡三拾众筹持续交付开发流程支撑创新业务
  • 如何在GitHub上创建个人博客
  • elasticsearch-head插件安装
  • LIGO、Virgo第三轮探测告捷,同时探测到一对黑洞合并产生的引力波事件 ...
  • 阿里云ACE认证学习知识点梳理
  • 关于Android全面屏虚拟导航栏的适配总结
  • 回归生活:清理微信公众号
  • ​如何在iOS手机上查看应用日志
  • #AngularJS#$sce.trustAsResourceUrl
  • #HarmonyOS:Web组件的使用
  • (pojstep1.1.1)poj 1298(直叙式模拟)
  • (附表设计)不是我吹!超级全面的权限系统设计方案面世了
  • (附源码)springboot“微印象”在线打印预约系统 毕业设计 061642
  • (附源码)ssm高校志愿者服务系统 毕业设计 011648
  • (删)Java线程同步实现一:synchronzied和wait()/notify()
  • (算法二)滑动窗口
  • (转)程序员技术练级攻略
  • (转)可以带来幸福的一本书
  • (转)视频码率,帧率和分辨率的联系与区别
  • (转载)利用webkit抓取动态网页和链接
  • ./configure、make、make install 命令
  • .h头文件 .lib动态链接库文件 .dll 动态链接库
  • .net core 依赖注入的基本用发
  • .Net Core缓存组件(MemoryCache)源码解析
  • .NET Remoting Basic(10)-创建不同宿主的客户端与服务器端
  • .Net 中的反射(动态创建类型实例) - Part.4(转自http://www.tracefact.net/CLR-and-Framework/Reflection-Part4.aspx)...
  • .NET 中什么样的类是可使用 await 异步等待的?
  • .Net(C#)常用转换byte转uint32、byte转float等
  • .net中生成excel后调整宽度