#include <iostream>
#include <Windows.h>
#include <tchar.h>
using namespace std;
int main()
{
SHELLEXECUTEINFO seo;
memset(&seo, 0, sizeof(SHELLEXECUTEINFO));
seo.cbSize = sizeof(SHELLEXECUTEINFO);
seo.fMask = SEE_MASK_NOCLOSEPROCESS;
seo.nShow = SW_SHOWNORMAL;
seo.lpVerb = _T("open");
seo.lpDirectory = _T("E:\\ResTxt");
seo.lpFile = _T("Test.txt");
//seo.lpFile = _T("notepad.exe");
//seo.lpFile = _T("www.baidu.com");
BOOL flag = ShellExecuteEx(&seo);//open file
if (flag == TRUE)
{
cout << "Success!"<<endl;
}
else
{
cout<<"False"<<endl;
}
Sleep(1000);//delay 1s
if (seo.hProcess != NULL)
{
TerminateProcess(seo.hProcess, 0);//close file
seo.hProcess = NULL;
}
system("pause");
return 0;
}
<span style="font-family: Arial, Helvetica, sans-serif;">参考:http://www.cppblog.com/SpringSnow/archive/2009/04/22/80719.html</span>