c++ ShellExecute 执行cmd命令

c++ ShellExecute 执行cmd命令,第1张

WinExec,

CreateProcess;

ShellExecute 

都能执行cmd命令,

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


 

C++

CString GetModuleDir() {
	HMODULE module = GetModuleHandle(0);
	wchar_t pFileName[MAX_PATH] = { 0 };
	GetModuleFileName(module, pFileName, MAX_PATH);
	CString csFullName(pFileName);
	int nPos = csFullName.ReverseFind('\');
	if (nPos < 0)
		return CString("");
	else
		return csFullName.Left(nPos) +"\" + csFullName.Right(csFullName.GetLength() - nPos - 1);

}





LPCWSTR stringToLPCWSTR(std::string orig)
{
	size_t size = orig.length();
	wchar_t* buffer = new wchar_t[size + 1];
	MultiByteToWideChar(CP_ACP, 0, orig.c_str(), size, buffer, size * sizeof(wchar_t));
	buffer[size] = 0;  //确保以 '' 结尾
	return buffer;
}







//重启程序自身
void ReStart()
{
	string sAppPath = CT2A(GetModuleDir());
	string sCmd &

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/921636.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-16
下一篇2022-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存