c - 打开外部程序

标签 c windows file console-application

我一直在尝试打开一个外部程序,例如用 C 语言打开编辑器。 我已经搜索了几个小时,但没有找到打开外部可执行文件的方法,例如从控制台应用程序打开 Skype 等。

这是我到目前为止的代码:

    /* fopen1.c */
#include <Windows.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

int main(int)
{
    FILE *fp;
    fp = fopen("C://Users/Jonte/Desktop/Skype.exe", "r");
}

如何打开外部文件? 谢谢你, 真挚地, 贝林

最佳答案

一种可能的方法 -

system("C:\\Windows\\notepad.exe");

ShellExecute(NULL, "open", "C:\\Windows\\notepad.exe", NULL, NULL, SW_SHOWDEFAULT);

或使用CreateProcess

VOID startup(LPCTSTR lpApplicationName)
{
  // additional information
  STARTUPINFO si;     
  PROCESS_INFORMATION pi;

  // set the size of the structures
  ZeroMemory( &si, sizeof(si) );
  si.cb = sizeof(si);
  ZeroMemory( &pi, sizeof(pi) );

  // start the program up
  CreateProcess( lpApplicationName,   // the path
  argv[1],        // 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
  ) 
  // Close process and thread handles. 
  CloseHandle( pi.hProcess );
  CloseHandle( pi.hThread );
}

关于c - 打开外部程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31379141/

相关文章:

windows - 具有 64 位 Outlook 的 32 位 MAPI 应用程序

c++ - .bat 脚本删除尾随空格

c - 如何从C中的文件中读取一行

asp.net-mvc - ASP.NET Web API 文件保存为 "BodyPart_3ded2bfb-40be-4183-b789-9301f93e90af"

windows - 使用 cmd 删除文件名前缀

c - getenv C 上的段错误?

c++ - wxFrame 缺少最大化按钮

c++ - 以下哪种方法可以安全地导出到 C++ dll 中?

c - 交换 char 数组中的元素

c - Opengl - 附加到纹理