第一例:打开cmd程序

这个很简单,书上就有其详细解释,故不再赘言。

代码如下:

 1 #include<windows.h> 
 2 #include<stdio.h>
 3 #include<stdlib.h>
 4 
 5 int main(int argc,char* argv[])
 6 {
 7     char szCommandLine[] = "cmd";
 8     STARTUPINFO si = {sizeof(si)};
 9     PROCESS_INFORMATION pi;
10     si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USEPOSITION;
11     si.wShowWindow = true;
12     si.dwX = 0;
13     si.dwY = 0;
14     
15     bool bRet = ::CreateProcess(
16                                 NULL,szCommandLine,
17                                 NULL,NULL,
18                                 false,CREATE_NEW_CONSOLE,
19                                 NULL,NULL,&si,&pi 
20                                 );
21     if(bRet)
22     {
23         printf("ThreadId:%d\n",pi.dwThreadId);
24         printf("ProcessId:%d\n",pi.dwProcessId);
25         system("pause");
26         ::CloseHandle(pi.hThread);
27         ::CloseHandle(pi.hProcess);
28         printf("关闭成功!\n");
29     }
30     return 0;
31 }

 

posted @ 2017-01-30 00:02  泛未分晨  阅读(198)  评论(0编辑  收藏  举报