ShellExecute 与 CreateProcess 调用外部程序

来源:互联网 发布:Linux 内核的dm-verity 编辑:程序博客网 时间:2024/04/28 16:08

1、ShellExecute(handle,"open","notepad.exe","c:/MyLog.log","",SW_SHOW );
2、ShellExecute(handle,"open","wordpad.exe","c:/MyLog.log","",SW_SHOW );
3、ShellExecute(handle,"open","c:/My.exe","c:/MyLog.log","",SW_SHOW );

在win2000 server中
执行命令(1)时,通过
执行命令(2)时,出现错误提示“找不到文件”XP下可以通过
执行命令(3)时,不能通过,也没有什么 提示

又特别地
  第3句改为 ShellExecute(handle,"open","c:/My.exe","c:/My Log.log","",SW_SHOW );
“My Love.mp3”分开有空格怎么办???
 
来自:bluebridge, 时间:2003-4-26 2:48:00, ID:1803811
其实不用exe文件参数,windows会自动找到log文件关联的执行程序的。去掉试试。  

 

////////////////////////////////////////////////-----------------------

 

/* Compile options needed: none*/ #include <windows.h>#include <stdio.h>void main(void){   PROCESS_INFORMATION pInfo;   STARTUPINFO         sInfo;   DWORD               exitCode;   sInfo.cb              = sizeof(STARTUPINFO);   sInfo.lpReserved      = NULL;   sInfo.lpReserved2     = NULL;   sInfo.cbReserved2     = 0;   sInfo.lpDesktop       = NULL;   sInfo.lpTitle         = NULL;   sInfo.dwFlags         = 0;   sInfo.dwX             = 0;   sInfo.dwY             = 0;   sInfo.dwFillAttribute = 0;   sInfo.wShowWindow     = SW_SHOW;   if (!CreateProcess(NULL,                "command.com /c dir c://*.bat",                      NULL,                      NULL,                      FALSE,                      0,                      NULL,                      NULL,                      &sInfo,                      &pInfo)) {      printf("ERROR: Cannot launch child process/n");      exit(1);   }   // Give the process time to execute and finish   WaitForSingleObject(pInfo.hProcess, 5000L);   if (GetExitCodeProcess(pInfo.hProcess, &exitCode))   {      switch(exitCode)      {         case STILL_ACTIVE: printf("Process is still active/n");                            break;         default:           printf("Exit code = %d/n", exitCode);                            break;      }   }   else {      printf("GetExitCodeProcess() failed/n");   }}

 

原创粉丝点击