zoukankan      html  css  js  c++  java
  • 执行外部文件的API

    1.HINSTANCE ShellExecute(         
        HWND hwnd,             // 父窗口句柄  NULL
        LPCTSTR lpOperation,   // 动作  "Open" "edit" "explore"..
        LPCTSTR lpFile,        // 要通过动作来操纵的文件对象 "notepad"
        LPCTSTR lpParameters,  // 若lpFile为可执行文件,lpParameters就是该可执行文件的命令行参数 "test.txt"
        LPCTSTR lpDirectory,   // 默认目录  NULL
        INT nShowCmd           // SW_HIDE ,SW_MAXIMIZE ,SW_MINIMIZE SW_SHOW SW_SHOWDEFAULT....
    );

    BOOL ShellExecuteEx(         
        LPSHELLEXECUTEINFO lpExecInfo
    );

    应用:
    打开一个应用程序:
             ShellExecute(this->m_hWnd,"Open","calc.exe","","",SW_SHOW);
    打开一个同系统程序相关连的文档:
             ShellExecute(this->m_hWnd,"open","c:\\abc.txt","","",SW_SHOW);
    打开一个网页:
             ShellExecute(this->m_hWnd,"open","http://www.google.com","","",SW_SHOW);
    激活相关程序,发送EMAIL:
             ShellExecute(this->m_hWnd,"open","maito:future_fighter123@yahoo.com.cn","","",SW_SHOW);
    用系统打印机打印文档:
             ShellExecute(this->m_hWnd,"print","c:\\abc.txt","","",SW_HIDE);
    用系统查找功能来查找指定文件:
             ShellExecute(this->m_hWnd,"find","c:\windows",NULL,NULL,SW_SHOW);
    启动一个程序,直到它运行结束:
     SHELLEXECUTEINFO ShExecInfo = {0};
     ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
     ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
     ShExecInfo.hwnd = NULL;
     ShExecInfo.lpVerb = NULL;
     ShExecInfo.lpFile = "c:\\MyProgram.exe";  
     ShExecInfo.lpParameters = ""; 
     ShExecInfo.lpDirectory = NULL;
     ShExecInfo.nShow = SW_SHOW;
     ShExecInfo.hInstApp = NULL; 
     ShellExecuteEx(&ShExecInfo);
     WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
         或者:
     PROCESS_INFORMATION ProcessInfo;
     STARTUPINFO StartupInfo; //This is an [in] parameter
     ZeroMemory(&StartupInfo, sizeof(StartupInfo));
     StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
     if(CreateProcess("c:\\winnt\\notepad.exe", NULL,
         NULL,NULL,FALSE,0,NULL,
         NULL,&StartupInfo,&ProcessInfo))
     {
         WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
         CloseHandle(ProcessInfo.hThread);
         CloseHandle(ProcessInfo.hProcess);
     } 
     else
     {
         MessageBox("The process could not be started...");
     }
    显示文件或文件夹的属性:
     SHELLEXECUTEINFO ShExecInfo ={0};
     ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
     ShExecInfo.fMask = SEE_MASK_INVOKEIDLIST ;
     ShExecInfo.hwnd = NULL;
     ShExecInfo.lpVerb = "properties";
     ShExecInfo.lpFile = "c:\\"; //can be a file as well
     ShExecInfo.lpParameters = "";
     ShExecInfo.lpDirectory = NULL;
     ShExecInfo.nShow = SW_SHOW;
     ShExecInfo.hInstApp = NULL;
     ShellExecuteEx(&ShExecInfo);


    2.UINT WinExec(
      LPCSTR lpCmdLine,   // 命令行参数
      UINT uCmdShow       // 显示方式,和ShowWindow的一样
    );

    3.BOOL CreateProcess(
      LPCTSTR lpApplicationName,
      LPTSTR lpCommandLine,
      LPSECURITY_ATTRIBUTES lpProcessAttributes,
      LPSECURITY_ATTRIBUTES lpThreadAttributes,
      BOOL bInheritHandles,
      DWORD dwCreationFlags,
      LPVOID lpEnvironment,
      LPCTSTR lpCurrentDirectory,
      LPSTARTUPINFO lpStartupInfo,
      LPPROCESS_INFORMATION lpProcessInformation
    );

  • 相关阅读:
    Twitter如何在数千台服务器上快速部署代码?
    系统架构师学习笔记_第六章(上)_连载
    使用IIS内置压缩功能,增加网站访问速度
    系统架构师学习笔记_第八章_连载
    微软企业库4.1学习笔记(十五)缓存模块3 使用数据库作为后端存储
    快速搞懂 SQL Server 的锁定和阻塞
    微软企业库4.1学习笔记(十四)缓存模块2 使用缓存模块进行开发
    微软企业库4.1学习笔记(十六)缓存模块4 服务器场中的缓存使用
    Agile PLM Engineering Collaboration
    EC Client Customizing EC Client 客户化
  • 原文地址:https://www.cnblogs.com/mywolrd/p/1930729.html
Copyright © 2011-2022 走看看