コード例 #1
0
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
0
ファイル: navigate.c プロジェクト: mikekap/wine
/* 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
0
ファイル: runas-windows.c プロジェクト: mitsuhiko/rust-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
0
ファイル: running.c プロジェクト: cfillion/vifm
/* 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
0
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
0
ファイル: Utils.cpp プロジェクト: nakedboov/WinClipCursor
	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
0
ファイル: umon.c プロジェクト: Moteesh/reactos
/***********************************************************************
 *           HlinkSimpleNavigateToString (URLMON.@)
 */
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
0
ファイル: plClientLoader.cpp プロジェクト: Hoikas/Plasma
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
0
ファイル: shlfolder.cpp プロジェクト: Moteesh/reactos
/***********************************************************************
 *  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
0
ファイル: shell.c プロジェクト: UIKit0/wine-1
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
0
ファイル: shellhlp.cpp プロジェクト: DamianSuess/LiteStep
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// LSShellExecuteEx
//
BOOL LSShellExecuteEx(LPSHELLEXECUTEINFOW lpExecInfo)
{
    PVOID pvOldValue = nullptr;
    LSDisableWow64FsRedirection(&pvOldValue);

    BOOL bReturn = ShellExecuteExW(lpExecInfo);

    LSRevertWow64FsRedirection(pvOldValue);
    return bReturn;
}
コード例 #12
0
NS_IMETHODIMP nsMailWinSearchHelper::RunSetup(bool aEnable)
{
  nsresult rv;
  if (!mCurProcD)
  {
    rv = NS_GetSpecialDirectory("CurProcD", getter_AddRefs(mCurProcD));
    NS_ENSURE_SUCCESS(rv, rv);
    rv = mCurProcD->Append(NS_LITERAL_STRING("WSEnable.exe"));
    NS_ENSURE_SUCCESS(rv, rv);
  }

  nsAutoString filePath;
  rv = mCurProcD->GetPath(filePath);
  NS_ENSURE_SUCCESS(rv, rv);

  // The parameters are of the format "1 <path>" for enabling and "0 <path>" for disabling
  nsAutoString params(aEnable ? NS_LITERAL_STRING("1 \"") : NS_LITERAL_STRING("0 \""));
  nsAutoString profDPath;
  rv = mProfD->GetPath(profDPath);
  NS_ENSURE_SUCCESS(rv, rv);
  params.Append(profDPath);
  params.Append(NS_LITERAL_STRING("\""));

  // We need an hWnd to cause UAC to pop up immediately
  // If GetForegroundWindow returns NULL, then the UAC prompt will still appear,
  // but minimized.
  HWND hWnd = GetForegroundWindow();

  SHELLEXECUTEINFOW executeInfo = {0};

  executeInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
  executeInfo.hwnd = hWnd;
  executeInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
  executeInfo.lpDirectory = NULL;
  executeInfo.lpFile = filePath.get();
  executeInfo.lpParameters = params.get();
  executeInfo.nShow = SW_SHOWNORMAL;

  DWORD dwRet;

  if (ShellExecuteExW(&executeInfo))
  {
    // We want to block until the program exits
    DWORD dwSignaled = WaitForSingleObject(executeInfo.hProcess, INFINITE);
    if (dwSignaled == WAIT_OBJECT_0)
      if (!GetExitCodeProcess(executeInfo.hProcess, &dwRet))
        dwRet = GetLastError();
  }
  else
    return NS_ERROR_ABORT;

  return SUCCEEDED(HRESULT_FROM_WIN32(dwRet)) ? NS_OK : NS_ERROR_FAILURE;
}
コード例 #13
0
ファイル: winjector-glue.c プロジェクト: liquidk/frida-core
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;
}
コード例 #14
0
ファイル: winmain.cpp プロジェクト: Drakesinger/Plasma
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;
}
コード例 #15
0
/**************************************************************************
* 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;
}
コード例 #16
0
ファイル: userinit.c プロジェクト: nsxz/reactos
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);
}
コード例 #17
0
ファイル: cpanelfolder.c プロジェクト: PatroxGaurab/wine
static HRESULT WINAPI IShellExecuteHookW_fnExecute(IShellExecuteHookW *iface,
        LPSHELLEXECUTEINFOW psei)
{
    ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
    static const WCHAR wCplopen[] = {'c','p','l','o','p','e','n','\0'};

    SHELLEXECUTEINFOW sei_tmp;
    PIDLCPanelStruct* pcpanel;
    WCHAR path[MAX_PATH];
    WCHAR params[MAX_PATH];
    BOOL ret;
    int l;

    TRACE("(%p)->execute(%p)\n", This, psei);

    if (!psei)
	return E_INVALIDARG;

    pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList));

    if (!pcpanel)
	return E_INVALIDARG;

    path[0] = '\"';
    /* Return value from MultiByteToWideChar includes terminating NUL, which
     * compensates for the starting double quote we just put in */
    l = MultiByteToWideChar(CP_ACP, 0, pcpanel->szName, -1, path+1, MAX_PATH-1);

    /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */
    path[l++] = '"';
    path[l] = '\0';

    MultiByteToWideChar(CP_ACP, 0, pcpanel->szName+pcpanel->offsDispName, -1, params, MAX_PATH);

    sei_tmp = *psei;
    sei_tmp.lpFile = path;
    sei_tmp.lpParameters = params;
    sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
    sei_tmp.lpVerb = wCplopen;

    ret = ShellExecuteExW(&sei_tmp);
    if (ret)
	return S_OK;
    else
	return S_FALSE;
}
コード例 #18
0
ファイル: startmenu.c プロジェクト: Dimillian/wine
static void exec_item(struct menu_item* item)
{
    LPITEMIDLIST abs_pidl;
    SHELLEXECUTEINFOW sei;

    abs_pidl = build_pidl(item);

    ZeroMemory(&sei, sizeof(sei));
    sei.cbSize = sizeof(sei);
    sei.fMask = SEE_MASK_IDLIST;
    sei.nShow = SW_SHOWNORMAL;
    sei.lpIDList = abs_pidl;

    ShellExecuteExW(&sei);

    CoTaskMemFree(abs_pidl);
}
コード例 #19
0
bool AdminAuthorization::execute(const QString &program, const QStringList &arguments)
{
    // AdminAuthorization::execute uses UAC to ask for admin privileges. If the user is no
    // administrator yet and the computer's policies are set to not use UAC (which is the case
    // in some corporate networks), the call to execute() will simply succeed and not at all
    // launch the child process. To avoid this, we detect this situation here and return early.
    if (!hasAdminRights())
    {
        QLatin1String key("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
                          "Policies\\System");
        QSettings registry(key, QSettings::NativeFormat);
        const QVariant enableLUA = registry.value(QLatin1String("EnableLUA"));

        if ((enableLUA.type() == QVariant::Int) && (enableLUA.toInt() == 0))
        {
            return false;
        }
    }

    const QString file = QDir::toNativeSeparators(program);
    const QString args = qt_create_commandline(QString(), arguments);

    SHELLEXECUTEINFOW shellExecuteInfo = { 0 };
    shellExecuteInfo.nShow = SW_HIDE;
    shellExecuteInfo.lpVerb = L"runas";
    shellExecuteInfo.lpFile = (wchar_t *)file.utf16();
    shellExecuteInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
    shellExecuteInfo.lpParameters = (wchar_t *)args.utf16();
    shellExecuteInfo.fMask = SEE_MASK_NOASYNC;

    qDebug() << QString::fromLatin1("Starting elevated process %1 with arguments: %2.").arg(file, args);

    if (ShellExecuteExW(&shellExecuteInfo))
    {
        qDebug() << "Finished starting elevated process.";
        return true;
    }
    else
    {
        qWarning() << QString::fromLatin1("Error while starting elevated process: %1, "
            "Error: %2").arg(program, windowsErrorString(GetLastError()));
    }

    return false;
}
コード例 #20
0
ファイル: sup.c プロジェクト: killbug2004/WinObjEx64
/*
* supRunAsAdmin
*
* Purpose:
*
* Restarts application requesting full admin rights.
*
*/
VOID supRunAsAdmin(
	VOID
	)
{
	SHELLEXECUTEINFOW shinfo;
	WCHAR szPath[MAX_PATH + 1];
	RtlSecureZeroMemory(&szPath, sizeof(szPath));
	if (GetModuleFileNameW(NULL, szPath, MAX_PATH)) {
		RtlSecureZeroMemory(&shinfo, sizeof(shinfo));
		shinfo.cbSize = sizeof(shinfo);
		shinfo.lpVerb = L"runas";
		shinfo.lpFile = szPath;
		shinfo.nShow = SW_SHOW;
		if (ShellExecuteExW(&shinfo)) {
			PostQuitMessage(0);
		}
	}
}
コード例 #21
0
ファイル: intshcut.c プロジェクト: HBelusca/NasuTek-Odyssey
static HRESULT WINAPI UniformResourceLocatorW_InvokeCommand(IUniformResourceLocatorW *url, PURLINVOKECOMMANDINFOW pCommandInfo)
{
    InternetShortcut *This = impl_from_IUniformResourceLocatorW(url);
    WCHAR app[64];
    HKEY hkey;
    static const WCHAR wszURLProtocol[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
    SHELLEXECUTEINFOW sei;
    DWORD res, type;
    HRESULT hres;

    TRACE("%p %p\n", This, pCommandInfo );

    if (pCommandInfo->dwcbSize < sizeof (URLINVOKECOMMANDINFOW))
        return E_INVALIDARG;

    if (pCommandInfo->dwFlags != IURL_INVOKECOMMAND_FL_USE_DEFAULT_VERB)
    {
        FIXME("(%p, %p): non-default verbs not implemented\n", url, pCommandInfo);
        return E_NOTIMPL;
    }

    hres = CoInternetParseUrl(This->url, PARSE_SCHEMA, 0, app, sizeof(app)/sizeof(WCHAR), NULL, 0);
    if(FAILED(hres))
        return E_FAIL;

    res = RegOpenKeyW(HKEY_CLASSES_ROOT, app, &hkey);
    if(res != ERROR_SUCCESS)
        return E_FAIL;

    res = RegQueryValueExW(hkey, wszURLProtocol, NULL, &type, NULL, NULL);
    RegCloseKey(hkey);
    if(res != ERROR_SUCCESS || type != REG_SZ)
        return E_FAIL;

    memset(&sei, 0, sizeof(sei));
    sei.cbSize = sizeof(sei);
    sei.lpFile = This->url;
    sei.nShow = SW_SHOW;

    if( ShellExecuteExW(&sei) )
        return S_OK;
    else
        return E_FAIL;
}
コード例 #22
0
ファイル: DllMain.cpp プロジェクト: Emiyasviel/Arianrhod
PVOID ProbeInvokeCreateProcessAddress()
{
    PVOID               Shell32, Shell32CreateProcessW, CreateProcessW;
    PLDR_MODULE         Shell32Module, MainModule;
    SHELLEXECUTEINFOW   ExecuteInfo;
    PIMAGE_NT_HEADERS   NtHeaders;

    Shell32 = Ldr::LoadDll(L"Shell32.dll");

    Shell32CreateProcessW = PtrAdd(Shell32, IATLookupRoutineRVAByHashNoFix(Shell32, KERNEL32_CreateProcessW));

    MainModule = FindLdrModuleByHandle(nullptr);

    RtlDuplicateUnicodeString(RTL_DUPSTR_ADD_NULL, &MainModule->FullDllName, &ProbeApplicationName);
    RtlInitUnicodeString(&ProbeCommandLine, L"ML_PROBE_APPLICATION_COMMAMD_LINE");

    ZeroMemory(&ExecuteInfo, sizeof(ExecuteInfo));

    ExecuteInfo.cbSize          = sizeof(ExecuteInfo);
    ExecuteInfo.fMask           = SEE_MASK_NOASYNC | SEE_MASK_FLAG_NO_UI;
    ExecuteInfo.lpVerb          = L"open";
    ExecuteInfo.lpFile          = ProbeApplicationName.Buffer;
    ExecuteInfo.lpParameters    = ProbeCommandLine.Buffer;
    ExecuteInfo.lpDirectory     = ProbeApplicationName.Buffer;
    ExecuteInfo.nShow           = SW_SHOW;

    *(PVOID *)&Shell32CreateProcessWIAT = Shell32CreateProcessW;
    *(PVOID *)&Shell32CreateProcessWPtr = *(PVOID *)Shell32CreateProcessWIAT;

    CreateProcessW = ProbeInvokeCreateProcessW;
    WriteProtectMemory(CurrentProcess, Shell32CreateProcessW, &CreateProcessW, sizeof(CreateProcessW));
    ShellExecuteExW(&ExecuteInfo);
    WriteProtectMemory(CurrentProcess, Shell32CreateProcessW, &Shell32CreateProcessWPtr, sizeof(Shell32CreateProcessWPtr));

    RtlFreeUnicodeString(&ProbeApplicationName);

    NtHeaders = RtlImageNtHeader(Shell32);

    if (InvokeReturnAddress < Shell32 || InvokeReturnAddress > PtrAdd(Shell32, NtHeaders->OptionalHeader.SizeOfImage))
        return nullptr;

    return InvokeReturnAddress;
}
コード例 #23
0
	void GenerateApk(std::wstring path )
	{
		//if ( !JREInstalled() )
		//{
		//	MessageBoxW(NULL, L"未安装 java 运行环境,无法生成 apk 安装包,请安装 java 运行环境后重试!", L"提示", MB_OK | MB_ICONINFORMATION);
		//	return;
		//}

		SHELLEXECUTEINFOW sei;
		memset(&sei, 0, sizeof(SHELLEXECUTEINFO)); 
		std::wstring installPath = GetExePath() + L"\\dependency\\Android\\Remote\\install.exe";
		wchar_t cmd[1024] = {0};
		wsprintfW(cmd, L"-i \"%s\" -o \"%s\"", GetExePath().c_str(), path.c_str());

		sei.cbSize = sizeof(SHELLEXECUTEINFO);
		sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_DOENVSUBST;
		sei.lpVerb = L"open";
		sei.lpFile = installPath.c_str();
		sei.lpParameters = cmd;
		sei.nShow = SW_HIDE;

		PVOID oldValue = NULL;
		if ( Is64Bit() && !oldValue )
		{
			HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
			pWow64DisableWow64FsRedirection foo = (pWow64DisableWow64FsRedirection)GetProcAddress(kernel32, "Wow64DisableWow64FsRedirection");
			foo(&oldValue);
		}

		ShellExecuteExW(&sei);
		WaitForSingleObject(sei.hProcess, INFINITE);
		CloseHandle(sei.hProcess);

		if ( Is64Bit() && oldValue )
		{
			HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
			pWow64RevertWow64FsRedirection foo = (pWow64RevertWow64FsRedirection)GetProcAddress(kernel32, "Wow64RevertWow64FsRedirection");
			foo(oldValue);
		}


	}
コード例 #24
0
nsresult LaunchHelper(nsAutoString& aPath, nsAutoString& aParams) {
  SHELLEXECUTEINFOW executeInfo = {0};

  executeInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
  executeInfo.hwnd = NULL;
  executeInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
  executeInfo.lpDirectory = NULL;
  executeInfo.lpFile = aPath.get();
  executeInfo.lpParameters = aParams.get();
  executeInfo.nShow = SW_SHOWNORMAL;

  if (ShellExecuteExW(&executeInfo))
    // Block until the program exits
    WaitForSingleObject(executeInfo.hProcess, INFINITE);
  else
    return NS_ERROR_ABORT;

  // We're going to ignore errors here since there's nothing we can do about
  // them, and helper.exe seems to return non-zero ret on success.
  return NS_OK;
}
コード例 #25
0
ファイル: rsync_util.cpp プロジェクト: Lessica/Acrosync-Demo
bool elevateProcess()
{
    // Elevate the process.
    wchar_t szPath[MAX_PATH];
    if (!GetModuleFileNameW(NULL, szPath, ARRAYSIZE(szPath))) {
		return false;
	}

    // Launch itself as administrator.
    SHELLEXECUTEINFOW sei = { sizeof(sei) };
    sei.lpVerb = L"runas";
    sei.lpFile = szPath;
    sei.hwnd = NULL;
    sei.nShow = SW_NORMAL;

    if (!ShellExecuteExW(&sei)) {
        DWORD dwError = GetLastError();
        if (dwError == ERROR_CANCELLED) {
			return false;
        }
    }
	return true;
}
コード例 #26
0
ファイル: languages.c プロジェクト: Strongc/reactos
/* Property page dialog callback */
INT_PTR CALLBACK
LanguagesPageProc(HWND hwndDlg,
                  UINT uMsg,
                  WPARAM wParam,
                  LPARAM lParam)
{
    SHELLEXECUTEINFOW shInputDll;

    switch (uMsg)
    {
        case WM_INITDIALOG:
            break;

        case WM_COMMAND:
            switch (LOWORD(wParam))
            {
                /* If "detail" button pressed */
                case IDC_DETAIL_BUTTON:
                    if (HIWORD(wParam) == BN_CLICKED)
                    {
                        memset(&shInputDll, 0x0, sizeof(SHELLEXECUTEINFOW));
                        shInputDll.cbSize = sizeof(shInputDll);
                        shInputDll.hwnd = hwndDlg;
                        shInputDll.lpVerb = L"open";
                        shInputDll.lpFile = L"RunDll32.exe";
                        shInputDll.lpParameters = L"shell32.dll,Control_RunDLL input.dll";
                        if (ShellExecuteExW(&shInputDll) == 0)
                        {
                            PrintErrorMsgBox(IDS_ERROR_INPUT_DLL);
                        }
                    }
                    break;
            }
            break;
    }
    return FALSE;
}
コード例 #27
0
ファイル: WINDOWSmain.cpp プロジェクト: enigma-dev/enigma-dev
void execute_program(std::string operation, std::string fname, std::string args, bool wait) {
  SHELLEXECUTEINFOW lpExecInfo;
  tstring tstr_operation = widen(operation);
  tstring tstr_fname = widen(fname);
  tstring tstr_args = widen(args);
  lpExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
  lpExecInfo.lpFile = tstr_fname.c_str();
  lpExecInfo.fMask = SEE_MASK_DOENVSUBST | SEE_MASK_NOCLOSEPROCESS;
  lpExecInfo.hwnd = enigma::hWnd;
  lpExecInfo.lpVerb = tstr_operation.c_str();
  lpExecInfo.lpParameters = tstr_args.c_str();
  WCHAR cDir[MAX_PATH];
  GetCurrentDirectoryW(MAX_PATH, cDir);
  lpExecInfo.lpDirectory = cDir;
  lpExecInfo.nShow = SW_SHOW;
  lpExecInfo.hInstApp = (HINSTANCE)SE_ERR_DDEFAIL;  //WINSHELLAPI BOOL WINAPI result;
  ShellExecuteExW(&lpExecInfo);

  //wait until a file is finished printing
  if (wait && lpExecInfo.hProcess != NULL) {
    ::WaitForSingleObject(lpExecInfo.hProcess, INFINITE);
    ::CloseHandle(lpExecInfo.hProcess);
  }
}
コード例 #28
0
ファイル: QQ2011.cpp プロジェクト: gabrielharry/Arianrhod
HRESULT
NTAPI
ShowDBClickPicture(
    PVOID   This,
    PWSTR   PicturePath,
    PRECT   ClickPosition,
    BOOL    FromHistoryIfFalse,
    PVOID   Unknown
)
{
    SHELLEXECUTEINFOW ShellExecueInfo;

    if (GetKeyState(VK_CONTROL) < 0)
        return StubShowDBClickPicture(This, PicturePath, ClickPosition, FromHistoryIfFalse, Unknown);

    ZeroMemory(&ShellExecueInfo, sizeof(ShellExecueInfo));
    ShellExecueInfo.cbSize  = sizeof(ShellExecueInfo);
    ShellExecueInfo.lpFile  = PicturePath;
    ShellExecueInfo.lpVerb  = L"open";

    ShellExecuteExW(&ShellExecueInfo);

    return S_OK;
}
コード例 #29
0
ファイル: aereg.cpp プロジェクト: cnh/BitMate
JNIEXPORT jint JNICALL 
Java_org_gudy_azureus2_platform_win32_access_impl_AEWin32AccessInterface_shellExecAndWaitW(
	JNIEnv*		env,
	jclass		cla, 
	jstring		_file,
	jstring		_params )
{
	WCHAR		file[2048];
	WCHAR		params[2048];

	if ( !jstringToCharsW( env, _file, file, sizeof( file ))){

		return(0);
	}

	if ( !jstringToCharsW( env, _params, params, sizeof( params ))){

		return(0);
	}

    SHELLEXECUTEINFOW shExecInfo;

    shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW);

    shExecInfo.fMask		= SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT;
    shExecInfo.hwnd			= NULL;
    shExecInfo.lpVerb		= L"runas";
    shExecInfo.lpFile		= file;
    shExecInfo.lpParameters = params;
    shExecInfo.lpDirectory	= NULL;
    shExecInfo.nShow		= SW_SHOWNORMAL;
    shExecInfo.hInstApp		= NULL;

    ShellExecuteExW(&shExecInfo);


	int res = (int)shExecInfo.hInstApp;

	if ( res <= 32 ){

		throwException( env, "shellExec", "ShellExecW failed", res );

		return( 0 );

	}else{

		HANDLE process = shExecInfo.hProcess;

		WaitForSingleObject( process, INFINITE );

		DWORD result;

		if ( GetExitCodeProcess( process, &result ) == 0 ){

			throwException( env, "shellExec", "GetExitCodeProcess failed", GetLastError());
		}

		CloseHandle( process );
		
		return((jint)result);
	}
};
コード例 #30
0
ファイル: portable.cpp プロジェクト: kevinoupeng/mydg
int portable_system(const char *command,const char *args,bool commandHasConsole)
{

  if (command==0) return 1;

  QCString fullCmd=command;
  fullCmd=fullCmd.stripWhiteSpace();
  if (fullCmd.at(0)!='"' && fullCmd.find(' ')!=-1)
  {
    // add quotes around command as it contains spaces and is not quoted already
    fullCmd="\""+fullCmd+"\"";
  }
  fullCmd += " ";
  fullCmd += args;
#ifndef NODEBUG
  Debug::print(Debug::ExtCmd,0,"Executing external command `%s`\n",fullCmd.data());
#endif

#if !defined(_WIN32) || defined(__CYGWIN__)
  (void)commandHasConsole;
  /*! taken from the system() manpage on my Linux box */
  int pid,status=0;

#ifdef _OS_SOLARIS // for Solaris we use vfork since it is more memory efficient

  // on Solaris fork() duplicates the memory usage
  // so we use vfork instead
  
  // spawn shell
  if ((pid=vfork())<0)
  {
    status=-1;
  }
  else if (pid==0)
  {
     execl("/bin/sh","sh","-c",fullCmd.data(),(char*)0);
     _exit(127);
  }
  else
  {
    while (waitpid(pid,&status,0 )<0)
    {
      if (errno!=EINTR)
      {
        status=-1;
        break;
      }
    }
  }
  return status;

#else  // Other Unices just use fork

  pid = fork();
  if (pid==-1)
  {
    perror("fork error");
	  return -1;
  }
  if (pid==0)
  {
    const char * argv[4];
    argv[0] = "sh";
    argv[1] = "-c";
    argv[2] = fullCmd.data();
    argv[3] = 0;
    execve("/bin/sh",(char * const *)argv,environ);
    exit(127);
  }
  for (;;)
  {
    if (waitpid(pid,&status,0)==-1)
    {
      if (errno!=EINTR) return -1;
    }
    else
    {
      if (WIFEXITED(status))
      {
        return WEXITSTATUS(status);
      }
      else
      {
        return status;
      }
    }
  }
#endif // !_OS_SOLARIS

#else // Win32 specific
  if (commandHasConsole)
  {
    return system(fullCmd);
  }
  else
  {
    // Because ShellExecuteEx can delegate execution to Shell extensions 
    // (data sources, context menu handlers, verb implementations) that 
    // are activated using Component Object Model (COM), COM should be 
    // initialized before ShellExecuteEx is called. Some Shell extensions 
    // require the COM single-threaded apartment (STA) type. 
    // For that case COM is initialized as follows
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

    QString commandw = QString::fromUtf8( command );
    QString argsw = QString::fromUtf8( args );

    // gswin32 is a GUI api which will pop up a window and run
    // asynchronously. To prevent both, we use ShellExecuteEx and
    // WaitForSingleObject (thanks to Robert Golias for the code)

    SHELLEXECUTEINFOW sInfo = {
      sizeof(SHELLEXECUTEINFOW),   /* structure size */
      SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI,  /* tell us the process
                                                       *  handle so we can wait till it's done | 
                                                       *  do not display msg box if error 
                                                       */
      NULL,                       /* window handle */
      NULL,                       /* action to perform: open */
      (LPCWSTR)commandw.ucs2(),   /* file to execute */
      (LPCWSTR)argsw.ucs2(),      /* argument list */ 
      NULL,                       /* use current working dir */
      SW_HIDE,                    /* minimize on start-up */
      0,                          /* application instance handle */
      NULL,                       /* ignored: id list */
      NULL,                       /* ignored: class name */
      NULL,                       /* ignored: key class */
      0,                          /* ignored: hot key */
      NULL,                       /* ignored: icon */
      NULL                        /* resulting application handle */
    };

    if (!ShellExecuteExW(&sInfo))
    {
      return -1;
    }
    else if (sInfo.hProcess)      /* executable was launched, wait for it to finish */
    {
      WaitForSingleObject(sInfo.hProcess,INFINITE); 
      /* get process exit code */
      DWORD exitCode;
      if (!GetExitCodeProcess(sInfo.hProcess,&exitCode))
      {
        exitCode = -1;
      }
      CloseHandle(sInfo.hProcess);
      return exitCode;
    }
  }
#endif

}