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
    );

  • 相关阅读:
    Flask11 Session、CSRF、注销session、利用端点自动跳转
    python学习笔记4-时间函数
    python学习笔记3-循环1
    python学习笔记2-条件语句
    python学习笔记1-基础语法
    sprintf系列函数
    sscanf非常的重要
    c++中.c_str和.c_data
    c++Map用法
    c语言sscanf总结
  • 原文地址:https://www.cnblogs.com/mywolrd/p/1930729.html
Copyright © 2011-2022 走看看