本文整理汇总了C++中ShellExecuteExW函数的典型用法代码示例。如果您正苦于以下问题:C++ ShellExecuteExW函数的具体用法?C++ ShellExecuteExW怎么用?C++ ShellExecuteExW使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ShellExecuteExW函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
bool OsShell::runExe(const QString& command, const QString& arguments, const QString& workingDir, bool asAdmin)
{
SHELLEXECUTEINFOW shExecInfo = {0};
shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
const QString commandPathUnc = toUncPath(command);
const QString workingDirNative = toNativeSeparators(workingDir);
shExecInfo.fMask = SEE_MASK_FLAG_NO_UI;
shExecInfo.hwnd = nullptr;
shExecInfo.lpVerb = asAdmin ? L"runas" : L"open";
shExecInfo.lpFile = (WCHAR*)commandPathUnc.utf16();
shExecInfo.lpParameters = arguments.isEmpty() ? nullptr : (WCHAR*)arguments.utf16();
shExecInfo.lpDirectory = (WCHAR*)workingDirNative.utf16();
shExecInfo.nShow = SW_SHOWNORMAL;
shExecInfo.hInstApp = nullptr;
if (ShellExecuteExW(&shExecInfo) == 0)
{
if (GetLastError() != ERROR_CANCELLED) // Operation canceled by the user
{
const QString errorString = ErrorStringFromLastError();
qInfo() << "ShellExecuteExW failed when trying to run" << commandPathUnc << "in" << workingDirNative;
qInfo() << errorString;
return false;
}
}
return true;
}
示例2: try_application_url
/* FIXME: urlmon should handle it */
static BOOL try_application_url(LPCWSTR url)
{
SHELLEXECUTEINFOW exec_info;
WCHAR app[64];
HKEY hkey;
DWORD res, type;
HRESULT hres;
static const WCHAR wszURLProtocol[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, app, sizeof(app)/sizeof(WCHAR), NULL, 0);
if(FAILED(hres))
return FALSE;
res = RegOpenKeyW(HKEY_CLASSES_ROOT, app, &hkey);
if(res != ERROR_SUCCESS)
return FALSE;
res = RegQueryValueExW(hkey, wszURLProtocol, NULL, &type, NULL, NULL);
RegCloseKey(hkey);
if(res != ERROR_SUCCESS || type != REG_SZ)
return FALSE;
TRACE("openning application %s\n", debugstr_w(app));
memset(&exec_info, 0, sizeof(exec_info));
exec_info.cbSize = sizeof(exec_info);
exec_info.lpFile = url;
exec_info.nShow = SW_SHOW;
return ShellExecuteExW(&exec_info);
}
示例3: rust_win_runas
DWORD rust_win_runas(LPCTSTR *cmd, LPCTSTR *params, int show)
{
DWORD code;
SHELLEXECUTEINFO sei = { sizeof(sei) };
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
sei.fMask = SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS;
sei.lpVerb = L"runas";
sei.lpFile = cmd;
sei.lpParameters = params;
sei.nShow = show ? SW_NORMAL : SW_HIDE;
if (ShellExecuteExW(&sei) == FALSE || sei.hProcess == NULL) {
return -1;
}
WaitForSingleObject(sei.hProcess, INFINITE);
if (GetExitCodeProcess(sei.hProcess, &code) == 0) {
return -1;
}
return code;
}
示例4: run_win_executable_as_evaluated
/* Returns non-zero on error, otherwise zero is returned. */
static int
run_win_executable_as_evaluated(const char full_path[])
{
wchar_t *utf16_path;
SHELLEXECUTEINFOW sei;
utf16_path = utf8_to_utf16(full_path);
memset(&sei, 0, sizeof(sei));
sei.cbSize = sizeof(sei);
sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS;
sei.lpVerb = L"runas";
sei.lpFile = utf16_path;
sei.lpParameters = NULL;
sei.nShow = SW_SHOWNORMAL;
if(!ShellExecuteExW(&sei))
{
const DWORD last_error = GetLastError();
free(utf16_path);
LOG_WERROR(last_error);
return last_error != ERROR_CANCELLED;
}
free(utf16_path);
CloseHandle(sei.hProcess);
return 0;
}
示例5: RegOpenKey
LRESULT SwitcherSettingsDialog::OnGetSchemata(WORD, WORD, HWND hWndCtl, BOOL&) {
HKEY hKey;
LSTATUS ret = RegOpenKey(HKEY_LOCAL_MACHINE, _T("Software\\Rime\\Weasel"), &hKey);
if (ret == ERROR_SUCCESS) {
WCHAR value[MAX_PATH];
DWORD len = sizeof(value);
DWORD type = 0;
DWORD data = 0;
ret = RegQueryValueExW(hKey, L"WeaselRoot", NULL, &type, (LPBYTE)value, &len);
if (ret == ERROR_SUCCESS && type == REG_SZ) {
WCHAR parameters[MAX_PATH + 37];
wcscpy_s<_countof(parameters)>(parameters, (std::wstring(L"/k \"") + value + L"\\rime-install.bat\"").c_str());
SHELLEXECUTEINFOW cmd = {
sizeof(SHELLEXECUTEINFO),
SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC,
hWndCtl,
L"open",
L"cmd",
parameters,
NULL,
SW_SHOW,
NULL, NULL, NULL, NULL, NULL, NULL, NULL
};
ShellExecuteExW(&cmd);
WaitForSingleObject(cmd.hProcess, INFINITE);
CloseHandle(cmd.hProcess);
api_->load_settings(reinterpret_cast<RimeCustomSettings *>(settings_));
Populate();
}
}
RegCloseKey(hKey);
return 0;
}
示例6: TryToSelfElevate
bool TryToSelfElevate(HWND hwnd)
{
HRESULT hRes = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (hRes != S_OK)
throw std::runtime_error("Cannot initialize COM library.");
wchar_t szPath[MAX_PATH];
if (::GetModuleFileNameW(NULL, szPath, ARRAYSIZE(szPath)) == 0)
RaiseError("TryToSelfElevate:\n");
SHELLEXECUTEINFOW sei = { sizeof(sei) };
sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_UNICODE | SEE_MASK_NOASYNC | SEE_MASK_NO_CONSOLE | /*SEE_MASK_NOCLOSEPROCESS |*/ SEE_MASK_HMONITOR;
sei.lpVerb = L"runas";
sei.lpFile = szPath;
sei.nShow = SW_SHOW;
sei.hMonitor = ::MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY);
if (!ShellExecuteExW(&sei))
{
DWORD dwError = GetLastError();
if (dwError != ERROR_CANCELLED)
RaiseError("TryToSelfElevate:\n");
// The user refused the elevation.
return false;
}
//if (sei.hProcess == nullptr)
// throw std::runtime_error("Cannot start new process.");
//::WaitForSingleObject(sei.hProcess, INFINITE);
return true;
}
示例7: HlinkSimpleNavigateToString
/***********************************************************************
* HlinkSimpleNavigateToString ([email protected])
*/
HRESULT WINAPI HlinkSimpleNavigateToString( LPCWSTR szTarget,
LPCWSTR szLocation, LPCWSTR szTargetFrameName, IUnknown *pUnk,
IBindCtx *pbc, IBindStatusCallback *pbsc, DWORD grfHLNF, DWORD dwReserved)
{
FIXME("%s %s %s %p %p %p %u %u partial stub\n", debugstr_w( szTarget ), debugstr_w( szLocation ),
debugstr_w( szTargetFrameName ), pUnk, pbc, pbsc, grfHLNF, dwReserved);
/* undocumented: 0 means HLNF_OPENINNEWWINDOW*/
if (!grfHLNF) grfHLNF = HLNF_OPENINNEWWINDOW;
if (grfHLNF == HLNF_OPENINNEWWINDOW)
{
SHELLEXECUTEINFOW sei;
static const WCHAR openW[] = { 'o', 'p', 'e', 'n', 0 };
memset(&sei, 0, sizeof(sei));
sei.cbSize = sizeof(sei);
sei.lpVerb = openW;
sei.nShow = SW_SHOWNORMAL;
sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NO_CONSOLE;
sei.lpFile = szTarget;
if (ShellExecuteExW(&sei)) return S_OK;
}
return E_NOTIMPL;
}
示例8: InitPhysX
static bool InitPhysX()
{
#ifdef HS_BUILD_FOR_WIN32
plSimulationMgr::Init();
if (!plSimulationMgr::GetInstance()) {
if (plFileInfo(s_physXSetupExe).Exists()) {
// launch the PhysX installer
SHELLEXECUTEINFOW info;
memset(&info, 0, sizeof(info));
info.cbSize = sizeof(info);
info.lpFile = s_physXSetupExe.AsString().to_wchar();
info.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC;
ShellExecuteExW(&info);
// wait for completion
WaitForSingleObject(info.hProcess, INFINITE);
// cleanup
CloseHandle(info.hProcess);
} else {
hsMessageBox("You must install PhysX before you can play URU.", "Error", hsMessageBoxNormal, hsMessageBoxIconError);
return false;
}
}
if (plSimulationMgr::GetInstance()) {
plSimulationMgr::GetInstance()->Suspend();
return true;
} else {
hsMessageBox("PhysX install failed. You will not be able to play URU.", "Error", hsMessageBoxNormal, hsMessageBoxIconError);
return false;
}
#else
return false;
#endif // HS_BUILD_FOR_WIN32
}
示例9: SHOpenFolderAndSelectItems
/***********************************************************************
* SHOpenFolderAndSelectItems
*
* Unimplemented.
*/
EXTERN_C HRESULT
WINAPI
SHOpenFolderAndSelectItems(LPITEMIDLIST pidlFolder,
UINT cidl,
PCUITEMID_CHILD_ARRAY apidl,
DWORD dwFlags)
{
ERR("SHOpenFolderAndSelectItems() is hackplemented\n");
PCIDLIST_ABSOLUTE pidlItem;
if (cidl)
{
/* Firefox sends a full pidl here dispite the fact it is a PCUITEMID_CHILD_ARRAY -_- */
if (ILGetNext(apidl[0]) != NULL)
{
pidlItem = apidl[0];
}
else
{
pidlItem = ILCombine(pidlFolder, apidl[0]);
}
}
else
{
pidlItem = pidlFolder;
}
CComPtr<IShellFolder> psfDesktop;
HRESULT hr = SHGetDesktopFolder(&psfDesktop);
if (FAILED_UNEXPECTEDLY(hr))
return hr;
STRRET strret;
hr = psfDesktop->GetDisplayNameOf(pidlItem, SHGDN_FORPARSING, &strret);
if (FAILED_UNEXPECTEDLY(hr))
return hr;
WCHAR wszBuf[MAX_PATH];
hr = StrRetToBufW(&strret, pidlItem, wszBuf, _countof(wszBuf));
if (FAILED_UNEXPECTEDLY(hr))
return hr;
WCHAR wszParams[MAX_PATH];
wcscpy(wszParams, L"/select,");
wcscat(wszParams, wszBuf);
SHELLEXECUTEINFOW sei;
memset(&sei, 0, sizeof sei);
sei.cbSize = sizeof sei;
sei.fMask = SEE_MASK_WAITFORINPUTIDLE;
sei.lpFile = L"explorer.exe";
sei.lpParameters = wszParams;
if (ShellExecuteExW(&sei))
return S_OK;
else
return E_FAIL;
}
示例10: WshShell3_Run
static HRESULT WINAPI WshShell3_Run(IWshShell3 *iface, BSTR cmd, VARIANT *style, VARIANT *WaitOnReturn, int *exit_code)
{
SHELLEXECUTEINFOW info;
int waitforprocess;
VARIANT s, w;
HRESULT hr;
TRACE("(%s %s %s %p)\n", debugstr_w(cmd), debugstr_variant(style), debugstr_variant(WaitOnReturn), exit_code);
VariantInit(&s);
hr = VariantChangeType(&s, style, 0, VT_I4);
if (FAILED(hr))
{
ERR("failed to convert style argument, 0x%08x\n", hr);
return hr;
}
VariantInit(&w);
hr = VariantChangeType(&w, WaitOnReturn, 0, VT_I4);
if (FAILED(hr))
{
ERR("failed to convert wait argument, 0x%08x\n", hr);
return hr;
}
memset(&info, 0, sizeof(info));
info.cbSize = sizeof(info);
waitforprocess = V_I4(&w);
info.fMask = waitforprocess ? SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS : SEE_MASK_DEFAULT;
info.lpFile = cmd;
info.nShow = V_I4(&s);
if (!ShellExecuteExW(&info))
{
TRACE("ShellExecute failed, %d\n", GetLastError());
return HRESULT_FROM_WIN32(GetLastError());
}
else
{
if (waitforprocess)
{
if (exit_code)
{
DWORD code;
GetExitCodeProcess(info.hProcess, &code);
*exit_code = code;
}
CloseHandle(info.hProcess);
}
else
if (exit_code) *exit_code = 0;
return S_OK;
}
}
示例11: LSShellExecuteEx
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// LSShellExecuteEx
//
BOOL LSShellExecuteEx(LPSHELLEXECUTEINFOW lpExecInfo)
{
PVOID pvOldValue = nullptr;
LSDisableWow64FsRedirection(&pvOldValue);
BOOL bReturn = ShellExecuteExW(lpExecInfo);
LSRevertWow64FsRedirection(pvOldValue);
return bReturn;
}
示例12: frida_winjector_helper_factory_spawn
void *
frida_winjector_helper_factory_spawn (const gchar * path, const gchar * parameters, FridaWinjectorPrivilegeLevel level, GError ** error)
{
HANDLE process_handle;
SHELLEXECUTEINFOW ei = { 0, };
WCHAR * path_utf16;
WCHAR * parameters_utf16;
CoInitializeEx (NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
ei.cbSize = sizeof (ei);
ei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC | SEE_MASK_FLAG_NO_UI
| SEE_MASK_UNICODE | SEE_MASK_WAITFORINPUTIDLE;
if (level == FRIDA_WINJECTOR_PRIVILEGE_LEVEL_ELEVATED)
ei.lpVerb = L"runas";
else
ei.lpVerb = L"open";
path_utf16 = (WCHAR *) g_utf8_to_utf16 (path, -1, NULL, NULL, NULL);
ei.lpFile = path_utf16;
parameters_utf16 =
(WCHAR *) g_utf8_to_utf16 (parameters, -1, NULL, NULL, NULL);
ei.lpParameters = parameters_utf16;
ei.nShow = SW_HIDE;
if (ShellExecuteExW (&ei))
{
process_handle = ei.hProcess;
}
else
{
process_handle = NULL;
g_set_error (error,
FRIDA_ERROR,
FRIDA_ERROR_PERMISSION_DENIED,
"Unable to spawn helper executable at '%s': 0x%08lx",
path, GetLastError ());
}
g_free (parameters_utf16);
g_free (path_utf16);
CoUninitialize ();
return process_handle;
}
示例13: InitPhysX
bool InitPhysX()
{
bool physXInstalled = false;
while (!physXInstalled)
{
plSimulationMgr::Init();
if (!plSimulationMgr::GetInstance())
{
int ret = hsMessageBox("PhysX is not installed, or an older version is installed.\nInstall new version? (Game will exit if you click \"No\")",
"Missing PhysX", hsMessageBoxYesNo);
if (ret == hsMBoxNo) // exit if no
return false;
// launch the PhysX installer
SHELLEXECUTEINFOW info;
memset(&info, 0, sizeof(info));
info.cbSize = sizeof(info);
info.lpFile = s_physXSetupExeName;
info.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC;
ShellExecuteExW(&info);
// let the user know what's going on
HWND waitingDialog = ::CreateDialog(gHInst, MAKEINTRESOURCE(IDD_LOADING), NULL, WaitingForPhysXDialogProc);
// run a loop to wait for it to quit, pumping the windows message queue intermittently
DWORD waitRet = WaitForSingleObject(info.hProcess, 100);
MSG msg;
while (waitRet == WAIT_TIMEOUT)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
waitRet = WaitForSingleObject(info.hProcess, 100);
}
// cleanup
CloseHandle(info.hProcess);
::DestroyWindow(waitingDialog);
}
else
{
plSimulationMgr::GetInstance()->Suspend();
physXInstalled = true;
}
}
return true;
}
示例14: ISF_Fonts_IContextMenu2_InvokeCommand
/**************************************************************************
* ISF_Fonts_IContextMenu_InvokeCommand()
*/
static HRESULT WINAPI ISF_Fonts_IContextMenu2_InvokeCommand(
IContextMenu2 *iface,
LPCMINVOKECOMMANDINFO lpcmi)
{
SHELLEXECUTEINFOW sei;
PIDLFontStruct * pfont;
SHFILEOPSTRUCTW op;
IGenericSFImpl * This = impl_from_IContextMenu2(iface);
TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
if (lpcmi->lpVerb == MAKEINTRESOURCEA(1) || lpcmi->lpVerb == MAKEINTRESOURCEA(2) || lpcmi->lpVerb == MAKEINTRESOURCEA(7))
{
ZeroMemory(&sei, sizeof(sei));
sei.cbSize = sizeof(sei);
sei.hwnd = lpcmi->hwnd;
sei.nShow = SW_SHOWNORMAL;
if (lpcmi->lpVerb == MAKEINTRESOURCEA(1))
sei.lpVerb = L"open";
else if (lpcmi->lpVerb == MAKEINTRESOURCEA(2))
sei.lpVerb = L"print";
else if (lpcmi->lpVerb == MAKEINTRESOURCEA(7))
sei.lpVerb = L"properties";
pfont = _ILGetFontStruct(This->apidl);
sei.lpFile = pfont->szName + pfont->offsFile;
if (ShellExecuteExW(&sei) == FALSE)
return E_FAIL;
}
else if (lpcmi->lpVerb == MAKEINTRESOURCEA(4))
{
FIXME("implement font copying\n");
return E_NOTIMPL;
}
else if (lpcmi->lpVerb == MAKEINTRESOURCEA(6))
{
ZeroMemory(&op, sizeof(op));
op.hwnd = lpcmi->hwnd;
op.wFunc = FO_DELETE;
op.fFlags = FOF_ALLOWUNDO;
pfont = _ILGetFontStruct(This->apidl);
op.pFrom = pfont->szName + pfont->offsFile;
SHFileOperationW(&op);
}
return S_OK;
}
示例15: StartAutoApplications
static VOID
StartAutoApplications(
IN INT clsid)
{
WCHAR szPath[MAX_PATH] = {0};
HRESULT hResult;
HANDLE hFind;
WIN32_FIND_DATAW findData;
SHELLEXECUTEINFOW ExecInfo;
size_t len;
TRACE("(%d)\n", clsid);
hResult = SHGetFolderPathW(NULL, clsid, NULL, SHGFP_TYPE_CURRENT, szPath);
len = wcslen(szPath);
if (!SUCCEEDED(hResult) || len == 0)
{
WARN("SHGetFolderPath() failed with error %lu\n", GetLastError());
return;
}
wcscat(szPath, L"\\*");
hFind = FindFirstFileW(szPath, &findData);
if (hFind == INVALID_HANDLE_VALUE)
{
WARN("FindFirstFile(%s) failed with error %lu\n", debugstr_w(szPath), GetLastError());
return;
}
do
{
if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (findData.nFileSizeHigh || findData.nFileSizeLow))
{
ZeroMemory(&ExecInfo, sizeof(SHELLEXECUTEINFOW));
ExecInfo.cbSize = sizeof(ExecInfo);
wcscpy(&szPath[len+1], findData.cFileName);
ExecInfo.lpVerb = L"open";
ExecInfo.lpFile = szPath;
ExecInfo.lpDirectory = NULL;
TRACE("Executing %s in directory %s\n",
debugstr_w(findData.cFileName), debugstr_w(szPath));
ShellExecuteExW(&ExecInfo);
}
} while (FindNextFileW(hFind, &findData));
FindClose(hFind);
}