zoukankan      html  css  js  c++  java
  • 让程序后台隐藏运行

    function exec_cmd_line(const sCmd: AnsiString; var nExitCode: Cardinal; nDefWaitTime: Cardinal = 10 * 1000): string;
    
    //const
    //  aExitCode_CreateProcessError = 222;
    
    var
      si: TStartupInfoA;
      pi: TProcessInformation;
    
      //aCurrDir: string;
    
      //aRet: Cardinal;
    
    
    begin
    
    
      FillChar(si, SizeOf(si), #0);
      FillChar(pi, SizeOf(pi), #0);
    
    //  Windows.GetStartupInfo(si);
      si.cb := SizeOf(si);
      si.dwFlags := STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW;
      si.wShowWindow := SW_HIDE;
    
    
    //BOOL WINAPI CreateProcess(
    //  LPCTSTR lpApplicationName,
    //  LPTSTR lpCommandLine,
    //  LPSECURITY_ATTRIBUTES lpProcessAttributes,
    //  LPSECURITY_ATTRIBUTES lpThreadAttributes,
    //  BOOL bInheritHandles,
    //  DWORD dwCreationFlags,
    //  LPVOID lpEnvironment,
    //  LPCTSTR lpCurrentDirectory,
    //  LPSTARTUPINFO lpStartupInfo,
    //  LPPROCESS_INFORMATION lpProcessInformation
    //);
    
      if Windows.CreateProcessA(
        nil, // LPCTSTR lpApplicationName, // pointer to name of executable module
        PAnsiChar(sCmd), //LPTSTR lpCommandLine,  // pointer to command line string
        nil, //LPSECURITY_ATTRIBUTES lpProcessAttributes,  // pointer to process security attributes
        nil, //LPSECURITY_ATTRIBUTES lpThreadAttributes,  // pointer to thread security attributes
        True, //BOOL bInheritHandles,  // handle inheritance flag
        0, //DWORD dwCreationFlags,  // creation flags
        nil, //LPVOID lpEnvironment,  // pointer to new environment block
        nil, //LPCTSTR lpCurrentDirectory,  // pointer to current directory name
        si, //LPSTARTUPINFO lpStartupInfo,  // pointer to STARTUPINFO
        pi //LPPROCESS_INFORMATION lpProcessInformation   // pointer to PROCESS_INFORMATION
        ) then begin
    
        if Windows.WaitForInputIdle(pi.hProcess, INFINITE) <> 0 then begin
    
        end;
    
        if Windows.WaitForSingleObject(pi.hProcess, nDefWaitTime) = Windows.WAIT_TIMEOUT then
          Windows.TerminateProcess(pi.hProcess, Windows.WAIT_TIMEOUT);
    
        Windows.GetExitCodeProcess(pi.hProcess, nExitCode);
    
      end
      else begin
        nExitCode := GetLastError;
      end;
    
      //nExitCode := nExitCode mod 256;
    
    end;

    http://bbs.2ccc.com/topic.asp?topicid=503890

  • 相关阅读:
    2013-9-29 通信原理学习笔记
    《大数据时代》阅读笔记
    《人人都是产品经理》阅读笔记一
    2013-8-13 信道接入技术研究学习
    2013-8-6 ubuntu基本操作
    2013-7-30 802.1X企业级加密
    2013-7-29 杂记
    2013-7-28 802.11n帧聚合
    2013-7-27 802.1X学习
    vue+node+mongoDB前后端分离个人博客(入门向)
  • 原文地址:https://www.cnblogs.com/findumars/p/6116011.html
Copyright © 2011-2022 走看看