我正在实现一个自动更新程序,它需要关闭当前正在运行的应用程序并启动安装程序。
我使用的代码是:
if (ExecuteAsAdmin(m_filePath))
PostQuitMessage(0);
BOOL ExecuteAsAdmin( LPCTSTR filePath )
{
SHELLEXECUTEINFO shExecInfo = {0};
shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
shExecInfo.fMask = SEE_MASK_CLASSNAME;
shExecInfo.lpClass = _T("exefile");
shExecInfo.hwnd = NULL;
shExecInfo.lpVerb = _T("runas");
shExecInfo.lpFile = filePath;
shExecInfo.lpParameters = NULL;
shExecInfo.lpDirectory = NULL;
shExecInfo.nShow = SW_NORMAL;
shExecInfo.hInstApp = NULL;
return ShellExecuteEx(&shExecInfo);
}
这够好吗?