MFC的EXE调用VBS,并获取VBS的返回值状态码

来源:互联网 发布:如何设置淘宝分流 编辑:程序博客网 时间:2024/05/21 10:38
VBS代码:

Dim age
age = 21
WScript.Quit age

MFC的EXE代码:

//获取EXE同目录下的VBS文件
TCHAR szExeSelfPath[_MAX_PATH] = {0};
::GetModuleFileName(NULL,szExeSelfPath,_MAX_PATH);
CString strExeSelfPath = szExeSelfPath;
strExeSelfPath = strExeSelfPath.Left(strExeSelfPath.ReverseFind('\\') + 1);
CString strVBSPath = strExeSelfPath + "test.vbs";

//执行VBS文件
DWORD dwExitCode;
SHELLEXECUTEINFO sei = {0};
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
sei.hwnd = NULL;
sei.lpVerb = NULL;
sei.lpFile = strVBSPath;
sei.lpDirectory = NULL;
sei.nShow = SW_HIDE;
sei.hInstApp = NULL;
ShellExecuteEx(&sei);

//获取VBS返回的状态码
::GetExitCodeProcess(sei.hProcess,&dwExitCode);

CString strExitCode;
strExitCode.Format("%d",dwExitCode);
AfxMessageBox(strExitCode);

 

0 0