码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-07-19 22:13:32      阅读:366      评论:0      收藏:0      [点我收藏+]

标签:

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

 

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

标签:

原文地址:http://www.cnblogs.com/zzhua/p/5686325.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!