当前位置:   article > 正文

c++ ShellExecute 执行cmd命令_c++ shellexecute cmd

c++ shellexecute cmd

WinExec,

CreateProcess;

ShellExecute 

都能执行cmd命令

ShellExecute 相对简单些,且可一次执行多行命令


 

C++

  1. CString GetModuleDir() {
  2. HMODULE module = GetModuleHandle(0);
  3. wchar_t pFileName[MAX_PATH] = { 0 };
  4. GetModuleFileName(module, pFileName, MAX_PATH);
  5. CString csFullName(pFileName);
  6. int nPos = csFullName.ReverseFind('\\');
  7. if (nPos < 0)
  8. return CString("");
  9. else
  10. return csFullName.Left(nPos) +"\\" + csFullName.Right(csFullName.GetLength() - nPos - 1);
  11. }
  12. LPCWSTR stringToLPCWSTR(std::string orig)
  13. {
  14. size_t size = orig.length();
  15. wchar_t* buffer = new wchar_t[size + 1];
  16. MultiByteToWideChar(CP_ACP, 0, orig.c_str(), size, buffer, size * sizeof(wchar_t));
  17. buffer[size] = 0; //确保以 '\0' 结尾
  18. return buffer;
  19. }
  20. //重启程序自身
  21. void ReStart()
  22. {
  23. string sAppPath = CT2A(GetModuleDir());
  24. string sCmd &
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/289728
推荐阅读
相关标签
  

闽ICP备14008679号