Example #1
0
BOOL DoStartStartupItems(ITrayWindow *Tray)
{
    DWORD dwWait;

    if (!bExplorerIsShell)
        return FALSE;

    if (!s_hStartupMutex)
    {
        // Accidentally, there is possibility that the system starts multiple Explorers
        // before startup of shell. We use a mutex to match the timing of shell initialization.
        s_hStartupMutex = CreateMutexW(NULL, FALSE, L"ExplorerIsShellMutex");
        if (s_hStartupMutex == NULL)
            return FALSE;
    }

    dwWait = WaitForSingleObject(s_hStartupMutex, INFINITE);
    TRACE("dwWait: 0x%08lX\n", dwWait);
    if (dwWait != WAIT_OBJECT_0)
    {
        TRACE("LastError: %ld\n", GetLastError());

        DoFinishStartupItems();
        return FALSE;
    }

    const DWORD dwWaitTotal = 3000;     // in milliseconds
    DWORD dwTick = GetTickCount();
    while (GetShellWindow() == NULL && GetTickCount() - dwTick < dwWaitTotal)
    {
        TrayProcessMessages(Tray);
    }

    if (GetShellWindow() == NULL)
    {
        DoFinishStartupItems();
        return FALSE;
    }

    // Check the volatile "StartupHasBeenRun" key
    HKEY hSessionKey, hKey;
    HRESULT hr = SHCreateSessionKey(KEY_WRITE, &hSessionKey);
    if (SUCCEEDED(hr))
    {
        ASSERT(hSessionKey);

        DWORD dwDisp;
        LONG Error = RegCreateKeyExW(hSessionKey, L"StartupHasBeenRun", 0, NULL,
                                     REG_OPTION_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp);
        RegCloseKey(hSessionKey);
        RegCloseKey(hKey);
        if (Error == ERROR_SUCCESS && dwDisp == REG_OPENED_EXISTING_KEY)
        {
            return FALSE;   // Startup programs has already been run
        }
    }

    return TRUE;
}
Example #2
0
static int dxva2_device_create9ex(AVHWDeviceContext *ctx, UINT adapter)
{
    DXVA2DevicePriv *priv = ctx->user_opaque;
    D3DPRESENT_PARAMETERS d3dpp = dxva2_present_params;
    D3DDISPLAYMODEEX modeex = {0};
    IDirect3D9Ex *d3d9ex = NULL;
    IDirect3DDevice9Ex *exdev = NULL;
    HRESULT hr;
    pDirect3DCreate9Ex *createD3DEx = (pDirect3DCreate9Ex *)GetProcAddress(priv->d3dlib, "Direct3DCreate9Ex");
    if (!createD3DEx)
        return AVERROR(ENOSYS);

    hr = createD3DEx(D3D_SDK_VERSION, &d3d9ex);
    if (FAILED(hr))
        return AVERROR_UNKNOWN;

    IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex, adapter, &modeex, NULL);

    d3dpp.BackBufferFormat = modeex.Format;

    hr = IDirect3D9Ex_CreateDeviceEx(d3d9ex, adapter, D3DDEVTYPE_HAL, GetShellWindow(),
                                     FF_D3DCREATE_FLAGS,
                                     &d3dpp, NULL, &exdev);
    if (FAILED(hr)) {
        IDirect3D9Ex_Release(d3d9ex);
        return AVERROR_UNKNOWN;
    }

    av_log(ctx, AV_LOG_VERBOSE, "Using D3D9Ex device.\n");
    priv->d3d9 = (IDirect3D9 *)d3d9ex;
    priv->d3d9device = (IDirect3DDevice9 *)exdev;
    return 0;
}
Example #3
0
INT WINAPI
_tWinMain(IN HINSTANCE hInstance,
          IN HINSTANCE hPrevInstance,
          IN LPTSTR lpCmdLine,
          IN INT nCmdShow)
{
    /*
    * Set our shutdown parameters: we want to shutdown the very last,
    * but before any TaskMgr instance (which has a shutdown level of 1).
    */
    SetProcessShutdownParameters(2, 0);

    InitRSHELL();

    TRACE("Explorer starting... Command line: %S\n", lpCmdLine);

#if !WIN7_COMPAT_MODE
    if (GetShellWindow() == NULL)
        bExplorerIsShell = TRUE;

    if (!bExplorerIsShell)
    {
        return StartWithCommandLine(hInstance);
    }
#else
    bExplorerIsShell = TRUE;
#endif

    return StartWithDesktop(hInstance);
}
Example #4
0
IDirect3DDevice9* CreateDevice9(HINSTANCE dll, IDirect3D9** d3d9, D3DADAPTER_IDENTIFIER9 *d3dai)
{
    qDebug("creating d3d9 device...");
    typedef IDirect3D9* (WINAPI *Create9Func)(UINT SDKVersion);
    Create9Func Create9 = (Create9Func)GetProcAddress(dll, "Direct3DCreate9");
    if (!Create9) {
        qWarning("Symbol not found: Direct3DCreate9");
        return NULL;
    }
    *d3d9 = Create9(D3D_SDK_VERSION);
    if (!(*d3d9)) {
        qWarning("Direct3DCreate9 failed");
        return NULL;
    }
    if (d3dai)
        DX_WARN((*d3d9)->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, d3dai));

    D3DPRESENT_PARAMETERS d3dpp;
    InitParameters(&d3dpp);
    DWORD flags = D3DCREATE_FPU_PRESERVE | D3DCREATE_MULTITHREADED | D3DCREATE_MIXED_VERTEXPROCESSING;
    IDirect3DDevice9 *d3d9dev = NULL;
    DX_ENSURE(((*d3d9)->CreateDevice(D3DADAPTER_DEFAULT,
                                     D3DDEVTYPE_HAL, GetShellWindow(),// GetDesktopWindow(), //GetShellWindow()?
                                     flags,
                                     &d3dpp, &d3d9dev))
              , NULL);
    qDebug("IDirect3DDevice9 created");
    return d3d9dev;
}
Example #5
0
static int dxva2_device_create9(AVHWDeviceContext *ctx, UINT adapter)
{
    DXVA2DevicePriv *priv = ctx->user_opaque;
    D3DPRESENT_PARAMETERS d3dpp = dxva2_present_params;
    D3DDISPLAYMODE d3ddm;
    HRESULT hr;
    pDirect3DCreate9 *createD3D = (pDirect3DCreate9 *)GetProcAddress(priv->d3dlib, "Direct3DCreate9");
    if (!createD3D) {
        av_log(ctx, AV_LOG_ERROR, "Failed to locate Direct3DCreate9\n");
        return AVERROR_UNKNOWN;
    }

    priv->d3d9 = createD3D(D3D_SDK_VERSION);
    if (!priv->d3d9) {
        av_log(ctx, AV_LOG_ERROR, "Failed to create IDirect3D object\n");
        return AVERROR_UNKNOWN;
    }

    IDirect3D9_GetAdapterDisplayMode(priv->d3d9, adapter, &d3ddm);

    d3dpp.BackBufferFormat = d3ddm.Format;

    hr = IDirect3D9_CreateDevice(priv->d3d9, adapter, D3DDEVTYPE_HAL, GetShellWindow(),
                                FF_D3DCREATE_FLAGS,
                                &d3dpp, &priv->d3d9device);
    if (FAILED(hr)) {
        av_log(ctx, AV_LOG_ERROR, "Failed to create Direct3D device\n");
        return AVERROR_UNKNOWN;
    }

    return 0;
}
/***********************************************************************
*		SetShellWindowEx (USER32.@)
* hwndShell =    Progman[Program Manager]
*                |-> SHELLDLL_DefView
* hwndListView = |   |-> SysListView32
*                |   |   |-> tooltips_class32
*                |   |
*                |   |-> SysHeader32
*                |
*                |-> ProxyTarget
*/
BOOL WINAPI SetShellWindowEx(HWND hwndShell, HWND hwndListView)
{
    BOOL ret;

    if (GetShellWindow())
        return FALSE;

    if (GetWindowLongW(hwndShell, GWL_EXSTYLE) & WS_EX_TOPMOST)
        return FALSE;

    if (hwndListView != hwndShell)
        if (GetWindowLongW(hwndListView, GWL_EXSTYLE) & WS_EX_TOPMOST)
            return FALSE;

    if (hwndListView && hwndListView!=hwndShell)
        SetWindowPos(hwndListView, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);

    SetWindowPos(hwndShell, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);

    SERVER_START_REQ(set_global_windows)
    {
        req->flags          = SET_GLOBAL_SHELL_WINDOWS;
        req->shell_window   = wine_server_user_handle( hwndShell );
        req->shell_listview = wine_server_user_handle( hwndListView );
        ret = !wine_server_call_err(req);
    }
    SERVER_END_REQ;

    return ret;
}
Example #7
0
bool DisplayManager::IsFullscreen(HWND hWnd) {
    HWND fg = GetForegroundWindow();
    if (hWnd == NULL || fg == NULL) {
        return false;
    }

    HWND shell = GetShellWindow();
    if (fg == shell) {
        return false;
    }

    HWND dt = GetDesktopWindow();
    if (fg == dt) {
        return false;
    }

    RECT wndRect = { 0 };
    GetWindowRect(fg, &wndRect);
    Monitor wm = MonitorAtWindow(hWnd);
    if ((wndRect.bottom - wndRect.top) == wm.Height() &&
            (wndRect.right - wndRect.left) == wm.Width()) {
        return true;
    }
    return false;
}
Example #8
0
BOOL IsAltTabWindow(HWND hwnd)
{
    long wndStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
    if(GetWindowTextLength(hwnd) == 0)
        return false;

    // Ignore desktop window.
    if (hwnd == GetShellWindow())
        return(false);

    if(wndStyle & WS_EX_TOOLWINDOW)
        return(false);

    // Start at the root owner
    HWND hwndWalk = GetAncestor(hwnd, GA_ROOTOWNER);

    // See if we are the last active visible popup
    HWND hwndTry;
    while ((hwndTry = GetLastActivePopup(hwndWalk)) != hwndTry)
    {
        if (IsWindowVisible(hwndTry))
            break;
        hwndWalk = hwndTry;
    }
    return hwndWalk == hwnd;
}
Example #9
0
HWND FindShellProxy(LPITEMIDLIST pidl)
{
    if (!g_SeparateFolders)
    {
        HWND shell = GetShellWindow();

        if (shell)
        {
            DbgPrint("Found main desktop.\n");
            return shell;
        }
    }
    else
    {
        DbgPrint("Separate folders setting enabled. Ignoring main desktop.\n");
    }

    HWND proxy = FindWindow(PROXY_DESKTOP_CLASS, NULL);
    if (proxy)
    {
        DbgPrint("Found proxy desktop.\n");
        return proxy;
    }

    return NULL;
}
Example #10
0
/**
 * It creates a Direct3D device usable for DXVA 2
 */
static int D3dCreateDevice(vlc_va_dxva2_t *va)
{
    /* */
    LPDIRECT3D9 (WINAPI *Create9)(UINT SDKVersion);
    Create9 = (void *)GetProcAddress(va->hd3d9_dll,
                                     TEXT("Direct3DCreate9"));
    if (!Create9) {
        msg_Err(va->log, "Cannot locate reference to Direct3DCreate9 ABI in DLL");
        return VLC_EGENERIC;
    }

    /* */
    LPDIRECT3D9 d3dobj;
    d3dobj = Create9(D3D_SDK_VERSION);
    if (!d3dobj) {
        msg_Err(va->log, "Direct3DCreate9 failed");
        return VLC_EGENERIC;
    }
    va->d3dobj = d3dobj;

    /* */
    D3DADAPTER_IDENTIFIER9 *d3dai = &va->d3dai;
    if (FAILED(IDirect3D9_GetAdapterIdentifier(va->d3dobj,
                                               D3DADAPTER_DEFAULT, 0, d3dai))) {
        msg_Warn(va->log, "IDirect3D9_GetAdapterIdentifier failed");
        ZeroMemory(d3dai, sizeof(*d3dai));
    }

    /* */
    D3DPRESENT_PARAMETERS *d3dpp = &va->d3dpp;
    ZeroMemory(d3dpp, sizeof(*d3dpp));
    d3dpp->Flags                  = D3DPRESENTFLAG_VIDEO;
    d3dpp->Windowed               = TRUE;
    d3dpp->hDeviceWindow          = NULL;
    d3dpp->SwapEffect             = D3DSWAPEFFECT_DISCARD;
    d3dpp->MultiSampleType        = D3DMULTISAMPLE_NONE;
    d3dpp->PresentationInterval   = D3DPRESENT_INTERVAL_DEFAULT;
    d3dpp->BackBufferCount        = 0;                  /* FIXME what to put here */
    d3dpp->BackBufferFormat       = D3DFMT_X8R8G8B8;    /* FIXME what to put here */
    d3dpp->BackBufferWidth        = 0;
    d3dpp->BackBufferHeight       = 0;
    d3dpp->EnableAutoDepthStencil = FALSE;

    /* Direct3D needs a HWND to create a device, even without using ::Present
    this HWND is used to alert Direct3D when there's a change of focus window.
    For now, use GetShellWindow, as it looks harmless */
    LPDIRECT3DDEVICE9 d3ddev;
    if (FAILED(IDirect3D9_CreateDevice(d3dobj, D3DADAPTER_DEFAULT,
                                       D3DDEVTYPE_HAL, GetShellWindow(),
                                       D3DCREATE_SOFTWARE_VERTEXPROCESSING |
                                       D3DCREATE_MULTITHREADED,
                                       d3dpp, &d3ddev))) {
        msg_Err(va->log, "IDirect3D9_CreateDevice failed");
        return VLC_EGENERIC;
    }
    va->d3ddev = d3ddev;

    return VLC_SUCCESS;
}
BOOL WINAPI DisableWinKey() 
{
	//http://ru.stackoverflow.com/q/510916/207326
	//Глобальный отваливается!
	threadId = GetWindowThreadProcessId(GetShellWindow(), nullptr);
	hHook = SetWindowsHookEx(WH_CBT, CBTProc, GetModuleHandleA("WinKeyKiller.dll"), threadId);
	return BOOL(hHook);
}
Example #12
0
static int create_device(struct lavc_ctx *s)
{
    DXVA2Context *ctx = s->hwdec_priv;
    pDirect3DCreate9      *createD3D = NULL;
    HRESULT hr;
    D3DPRESENT_PARAMETERS d3dpp = {0};
    D3DDISPLAYMODE        d3ddm;
    UINT adapter = D3DADAPTER_DEFAULT;

    if (s->hwdec_info && s->hwdec_info->hwctx && s->hwdec_info->hwctx->d3d_ctx) {
        ctx->d3d9device = s->hwdec_info->hwctx->d3d_ctx->d3d9_device;
        if (ctx->d3d9device) {
            IDirect3D9_AddRef(ctx->d3d9device);
            MP_VERBOSE(ctx, "Using VO-supplied device %p.\n", ctx->d3d9device);
            return 0;
        }
    }

    ctx->d3dlib = LoadLibrary(L"d3d9.dll");
    if (!ctx->d3dlib) {
        MP_ERR(ctx, "Failed to load D3D9 library\n");
        goto fail;
    }

    createD3D = (pDirect3DCreate9 *)GetProcAddress(ctx->d3dlib, "Direct3DCreate9");
    if (!createD3D) {
        MP_ERR(ctx, "Failed to locate Direct3DCreate9\n");
        goto fail;
    }

    ctx->d3d9 = createD3D(D3D_SDK_VERSION);
    if (!ctx->d3d9) {
        MP_ERR(ctx, "Failed to create IDirect3D object\n");
        goto fail;
    }

    IDirect3D9_GetAdapterDisplayMode(ctx->d3d9, adapter, &d3ddm);
    d3dpp.Windowed         = TRUE;
    d3dpp.BackBufferWidth  = 640;
    d3dpp.BackBufferHeight = 480;
    d3dpp.BackBufferCount  = 0;
    d3dpp.BackBufferFormat = d3ddm.Format;
    d3dpp.SwapEffect       = D3DSWAPEFFECT_DISCARD;
    d3dpp.Flags            = D3DPRESENTFLAG_VIDEO;

    hr = IDirect3D9_CreateDevice(ctx->d3d9, adapter, D3DDEVTYPE_HAL, GetShellWindow(),
                                 D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
                                 &d3dpp, &ctx->d3d9device);
    if (FAILED(hr)) {
        MP_ERR(ctx, "Failed to create Direct3D device\n");
        goto fail;
    }

    return 0;

fail:
    return -1;
}
Example #13
0
BOOL IsAnyDesktopRunning()
{
	HINSTANCE hUser32 = GetModuleHandle(TEXT("user32"));

	SetShellWindow = (BOOL(WINAPI*)(HWND)) GetProcAddress(hUser32, "SetShellWindow");
	SetShellWindowEx = (BOOL(WINAPI*)(HWND,HWND)) GetProcAddress(hUser32, "SetShellWindowEx");

	return GetShellWindow() != 0;
}
Example #14
0
bool VideoDecoderDXVAPrivate::D3dCreateDeviceFallback()
{
    qDebug("Fallback to d3d9");
    typedef IDirect3D9* (WINAPI *Create9Func)(UINT SDKVersion);
    Create9Func Create9 = (Create9Func)GetProcAddress(hd3d9_dll, "Direct3DCreate9");
    if (!Create9) {
        qWarning("Cannot locate reference to Direct3DCreate9 ABI in DLL");
        return false;
    }
    d3dobj = Create9(D3D_SDK_VERSION);
    if (!d3dobj) {
        qWarning("Direct3DCreate9 failed");
        return false;
    }
    if (FAILED(d3dobj->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &d3dai))) {
        qWarning("IDirect3D9->GetAdapterIdentifier failed");
        ZeroMemory(&d3dai, sizeof(d3dai));
        return false;
    }
    vendor = getVendorName(&d3dai);
    description = QString().sprintf("DXVA2 (%.*s, vendor %lu(%s), device %lu, revision %lu)",
                                    sizeof(d3dai.Description), d3dai.Description,
                                    d3dai.VendorId, qPrintable(vendor), d3dai.DeviceId, d3dai.Revision);
    //if (copy_uswc)
      //  copy_uswc = vendor.toLower() == "intel";
    qDebug("DXVA2 description:  %s", description.toUtf8().constData());

    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    // use mozilla's parameters
    d3dpp.Flags                  = D3DPRESENTFLAG_VIDEO;
    d3dpp.Windowed               = TRUE;
    d3dpp.hDeviceWindow          = ::GetShellWindow(); //NULL;
    d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;
    //d3dpp.MultiSampleType        = D3DMULTISAMPLE_NONE;
    //d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_DEFAULT;
    d3dpp.BackBufferCount        = 1; //0;                  /* FIXME what to put here */
    d3dpp.BackBufferFormat       = D3DFMT_UNKNOWN; //D3DFMT_X8R8G8B8;    /* FIXME what to put here */
    d3dpp.BackBufferWidth        = 1; //0;
    d3dpp.BackBufferHeight       = 1; //0;
    //d3dpp.EnableAutoDepthStencil = FALSE;
    DWORD flags = D3DCREATE_FPU_PRESERVE | D3DCREATE_MULTITHREADED | D3DCREATE_MIXED_VERTEXPROCESSING;
    if (FAILED(d3dobj->CreateDevice(D3DADAPTER_DEFAULT,
                                   D3DDEVTYPE_HAL, GetShellWindow(),// GetDesktopWindow(), //GetShellWindow()?
                                   flags,
                                   &d3dpp, &d3ddev))) {
        qWarning("IDirect3D9->CreateDevice failed");
        d3ddev = 0;
        return false;
    }
    qDebug("IDirect3DDevice9 created....");
    return true;
}
Example #15
0
void LSP_InitializeHooks()
{
	HWND shellWindow = GetShellWindow();
	GetWindowThreadProcessId(shellWindow, &explorerPid);

	MH_CreateHookApi(L"kernelbase.dll", "RegOpenKeyExA", ProcessLSPRegOpenKeyExA, (void**)&g_origRegOpenKeyExA);

	if (CoreIsDebuggerPresent())
	{
		MH_CreateHookApi(L"ntdll.dll", "NtQueryInformationProcess", NtQueryInformationProcessHook, (void**)&origQIP);
		MH_CreateHookApi(L"ntdll.dll", "NtClose", NtCloseHook, (void**)&origClose);
	}

	MH_EnableHook(MH_ALL_HOOKS);
}
Example #16
0
// Поставить хук в процесс шелла (explorer.exe)
bool CDefaultTerminal::CheckShellWindow()
{
	bool bHooked = false;
	HWND hFore = GetForegroundWindow();
	HWND hDesktop = GetDesktopWindow(); //csrss.exe on Windows 8
	HWND hShell = GetShellWindow();
	HWND hTrayWnd = FindWindowEx(NULL, NULL, L"Shell_TrayWnd", NULL);
	DWORD nDesktopPID = 0, nShellPID = 0, nTrayPID = 0, nForePID = 0;

	if (!bHooked && hShell)
	{
		if (GetWindowThreadProcessId(hShell, &nShellPID) && nShellPID)
		{
			bHooked = CheckForeground(hShell, nShellPID, false);
		}
	}

	if (!bHooked && hTrayWnd)
	{
		if (GetWindowThreadProcessId(hTrayWnd, &nTrayPID) && nTrayPID
			&& (nTrayPID != nShellPID))
		{
			bHooked = CheckForeground(hTrayWnd, nTrayPID, false);
		}
	}

	if (!bHooked && hDesktop)
	{
		if (GetWindowThreadProcessId(hDesktop, &nDesktopPID) && nDesktopPID
			&& (nDesktopPID != nTrayPID) && (nDesktopPID != nShellPID))
		{
			bHooked = CheckForeground(hDesktop, nDesktopPID, false);
		}
	}

	// Поскольку это выполняется на старте, то ConEmu могли запустить специально
	// для установки перехвата терминала. Поэтому нужно проверить и ForegroundWindow!
	if (hFore)
	{
		if (GetWindowThreadProcessId(hFore, &nForePID)
			&& (nForePID != nShellPID) && (nForePID != nDesktopPID) && (nForePID != nTrayPID))
		{
			CheckForeground(hFore, nForePID, false);
		}
	}

	return bHooked;
}
// This must be run before the konvergo main window switches to FS mode.
void initD3DDevice(void)
{
  // Boilerplate for creating a "blank" D3D device.
  // Most of this is copied from FFmpeg (LGPL).
  pDirect3DCreate9 *createD3D = NULL;
  HRESULT hr;
  D3DPRESENT_PARAMETERS d3dpp = {};
  D3DDISPLAYMODE        d3ddm;
  UINT adapter = D3DADAPTER_DEFAULT;

  HMODULE d3dlib = LoadLibraryW(L"d3d9.dll");
  if (!d3dlib) {
      QLOG_ERROR() << "Failed to load D3D9 library";
      return;
  }

  createD3D = (pDirect3DCreate9 *)GetProcAddress(d3dlib, "Direct3DCreate9");
  if (!createD3D) {
      QLOG_ERROR() << "Failed to locate Direct3DCreate9";
      return;
  }

  IDirect3D9 *d3d9 = createD3D(D3D_SDK_VERSION);
  if (!d3d9) {
      QLOG_ERROR() << "Failed to create IDirect3D object";
      return;
  }

  IDirect3D9_GetAdapterDisplayMode(d3d9, adapter, &d3ddm);
  d3dpp.Windowed         = TRUE;
  d3dpp.BackBufferWidth  = 640;
  d3dpp.BackBufferHeight = 480;
  d3dpp.BackBufferCount  = 0;
  d3dpp.BackBufferFormat = d3ddm.Format;
  d3dpp.SwapEffect       = D3DSWAPEFFECT_DISCARD;
  d3dpp.Flags            = D3DPRESENTFLAG_VIDEO;

  hr = IDirect3D9_CreateDevice(d3d9, adapter, D3DDEVTYPE_HAL, GetShellWindow(),
                                D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
                                &d3dpp, &d3ddevice);
  if (FAILED(hr)) {
    QLOG_ERROR() << "Failed to create Direct3D device";
    return;
  }

  QLOG_INFO() << "Successfully created a Direct3D device";
};
Example #18
0
BOOL IsAltTabWindow(HWND hwnd)
{
	if (hwnd == GetShellWindow())   //Desktop
		return false;
	// Start at the root owner
	HWND hwndWalk = GetAncestor(hwnd, GA_ROOTOWNER);

	// See if we are the last active visible popup
	HWND hwndTry;
	while ((hwndTry = GetLastActivePopup(hwndWalk)) != hwndTry) 
	{
		if (IsWindowVisible(hwndTry)) 
			break;
		hwndWalk = hwndTry;
	}
	return hwndWalk == hwnd;
}
Example #19
0
bool isActiveWindowFullscreen()
{
	HWND activeHwnd = GetForegroundWindow();
	if (activeHwnd == GetShellWindow()) return 0;

	HMONITOR activeMonitor = MonitorFromWindow(activeHwnd, MONITOR_DEFAULTTONEAREST);

	MONITORINFO activeMonitorInfo;
	activeMonitorInfo.cbSize = sizeof(MONITORINFO);
	GetMonitorInfo(activeMonitor, &activeMonitorInfo);

	RECT activeHwndRect;
	GetWindowRect(activeHwnd, &activeHwndRect);

	return (activeHwndRect.top <= activeMonitorInfo.rcMonitor.top + 1 &&
		activeHwndRect.bottom >= activeMonitorInfo.rcMonitor.bottom - 1 &&
		activeHwndRect.left <= activeMonitorInfo.rcMonitor.left + 1 &&
		activeHwndRect.right >= activeMonitorInfo.rcMonitor.right - 1);
}
BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam )
{
    char WindowTitle[ DEFAULT_BUFLEN ];

    if( hwnd == GetShellWindow() )
        return false;

    //only search on main window names. If you need window in window search than enable this
//	HWND hwndroot = GetAncestor(hwnd, GA_ROOTOWNER);
//	if(
//		GetWindow( hwnd, GW_OWNER ) == 0
//		||
//		GetAncestor( hwnd, GA_PARENT )
//		IsAltTabWindow( hwnd ) == FALSE
//		hwndroot == GetLastVisibleActivePopUpOfWindow( hwndroot )
//		hwndroot != GetShellWindow()
//		hwnd != hwndroot
//		)
//		return TRUE;

    if( IsWindowVisible( hwnd ) == FALSE )
        return TRUE;

//	RECT WindowSize;
//	GetClientRect( hwnd, &WindowSize );
//	if( WindowSize.right <= 32 || WindowSize.bottom <= 32 )
//		return true;

    GetWindowText( hwnd, WindowTitle, sizeof( WindowTitle ) );

    //window without a name
    if( WindowTitle[0] == 0 )
        return TRUE;

    ProcessNameList *pIO = (ProcessNameList*)lParam;

    pIO->Count++;
    pIO->Names.push_back( _strdup( WindowTitle ) );

    return TRUE;
}
Example #21
0
bool isAltTabWindow(HWND window)
{
    if (!window || window == GetShellWindow())
        return false;

    HWND root = GetAncestor(window, GA_ROOTOWNER);

    if (getLastVisibleActivePopUpOfWindow(root) != window)
        return false;

    const QString cls = windowClass(window);
	COPYQ_LOG( QString("cls: \"%1\"").arg(cls) );
    return !cls.isEmpty()
            && cls != "Shell_TrayWnd"
            && cls != "Shell_SecondaryTrayWnd"
            && cls != "DV2ControlHost"
            && cls != "MsgrIMEWindowClass"
            && cls != "SysShadow"
            && cls != "Button"
            && !cls.startsWith("WMP9MediaBarFlyout");
}
Example #22
0
void DirectXMesh::CreateDevice() {
  mMesh = NULL;
  pd3d9 = NULL;
  pd3d9Device = NULL;

  HRESULT hr;

  pd3d9 = Direct3DCreate9(D3D_SDK_VERSION);

  D3DPRESENT_PARAMETERS fakeParams;
  fakeParams.BackBufferWidth = 320;
  fakeParams.BackBufferHeight = 240;
  fakeParams.BackBufferFormat = D3DFMT_X8R8G8B8;
  fakeParams.BackBufferCount = 1;
  fakeParams.MultiSampleType = D3DMULTISAMPLE_NONE;
  fakeParams.MultiSampleQuality = 0;
  fakeParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
  fakeParams.hDeviceWindow = GetShellWindow();
  fakeParams.Windowed = true;
  fakeParams.Flags = 0;
  fakeParams.FullScreen_RefreshRateInHz = 0;
  fakeParams.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
  fakeParams.EnableAutoDepthStencil = false;

  hr = pd3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL,
                           D3DCREATE_SOFTWARE_VERTEXPROCESSING, &fakeParams,
                           &pd3d9Device);
  if(FAILED(hr))
  {
    hr = pd3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, NULL,
                             D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                             &fakeParams, &pd3d9Device);
    if(FAILED(hr))
    {
      SAFE_RELEASE( pd3d9 )
    }
  }
}
Example #23
0
TStatus GetUnElevatedToken(CAutoHandle& hToken)
{
	HWND hShellWnd = GetShellWindow();
	if(hShellWnd == NULL)
	{
		SW_TSTATUS_RET(SW_ERR_WND_NOT_FOUND, L"GetShellWindow() return NULL");
	}
	DWORD dwShellPID = 0;
	GetWindowThreadProcessId(hShellWnd, &dwShellPID);
	SW_WINBOOL_RET(dwShellPID != 0);

	CAutoHandle hShellProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwShellPID);
	SW_WINBOOL_RET(hShellProcess.IsValid());

	CAutoHandle hShellProcessToken;

	SW_WINBOOL_RET(OpenProcessToken(hShellProcess, TOKEN_DUPLICATE, &hShellProcessToken));

	const DWORD dwTokenRights = TOKEN_QUERY | TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE | TOKEN_ADJUST_DEFAULT | TOKEN_ADJUST_SESSIONID;
	SW_WINBOOL_RET(DuplicateTokenEx(hShellProcessToken, dwTokenRights, NULL, SecurityImpersonation, TokenPrimary, &hToken));

	SW_RETURN_SUCCESS;
}
Example #24
0
// Поставить хук в процесс шелла (explorer.exe)
bool CDefaultTerminal::CheckShellWindow()
{
	bool bHooked = false;
	HWND hDesktop = GetDesktopWindow(); //csrss.exe on Windows 8
	HWND hShell = GetShellWindow();
	HWND hTrayWnd = FindWindowEx(NULL, NULL, L"Shell_TrayWnd", NULL);
	DWORD nDesktopPID = 0, nShellPID = 0, nTrayPID = 0;

	if (!bHooked && hShell)
	{
		if (GetWindowThreadProcessId(hShell, &nShellPID) && nShellPID)
		{
			bHooked = CheckForeground(hShell, nShellPID, false);
		}
	}

	if (!bHooked && hTrayWnd)
	{
		if (GetWindowThreadProcessId(hTrayWnd, &nTrayPID) && nTrayPID
			&& (nTrayPID != nShellPID))
		{
			bHooked = CheckForeground(hTrayWnd, nTrayPID, false);
		}
	}

	if (!bHooked && hDesktop)
	{
		if (GetWindowThreadProcessId(hDesktop, &nDesktopPID) && nDesktopPID
			&& (nDesktopPID != nTrayPID) && (nDesktopPID != nShellPID))
		{
			bHooked = CheckForeground(hDesktop, nDesktopPID, false);
		}
	}

	return bHooked;
}
Example #25
0
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
	DWORD dwStyle = GetWindowLongPtr(hwnd, GWL_STYLE);
	DWORD dwStyleEx = GetWindowLongPtr(hwnd, GWL_EXSTYLE);

	if( (dwStyle & WS_VISIBLE) && !(dwStyleEx & WS_EX_TOPMOST) )
	{
		HWND g_hwndShell = GetShellWindow();
		HWND g_deskWindow = GetDesktopWindow();
		HWND hwndOwner, hwndTmp = hwnd;

		do {
			hwndOwner = hwndTmp;
			hwndTmp = GetWindow(hwndTmp, GW_OWNER);
		} while (hwndTmp && (hwndTmp != g_hwndShell) && (hwndTmp != g_deskWindow)); // service messages

		if( (hwnd == hwndOwner) && ( hwndOwner != g_hwndShell ) )
		{
			((std::list<HWND>*)lParam)->push_back(hwndOwner);
		}
	}

	return (TRUE);
}
Example #26
0
//
// IService::Stop
//
HRESULT ExplorerService::Stop()
{
    if (m_dwThreadID)
    {
        HWND hProgman = FindWindow(_T("Progman"), NULL);
        SendMessage(hProgman, 0x44D, 0, 0);
        PostMessage(hProgman, WM_QUIT, 0, 1);
    }

    if (m_hExplorerThread)
    {
        if (WaitForSingleObject(m_hExplorerThread, 1000) != WAIT_OBJECT_0)
        {
            TerminateThread(m_hExplorerThread, 0);
        }

        TRACE("%p", GetShellWindow());

        CloseHandle(m_hExplorerThread);
        m_hExplorerThread = nullptr;
    }

    return S_OK;
}
Example #27
0
/**
 * This function is only called in non-native mode
 * Its responsibility is to initialize D3D, create a device and a device manager
 * and call SetD3DDeviceManager with it.
 */
HRESULT CDecDXVA2::InitD3D()
{
  HRESULT hr = S_OK;

  if (FAILED(hr = LoadDXVA2Functions())) {
    DbgLog((LOG_ERROR, 10, L"-> Failed to load DXVA2 DLL functions"));
    return E_FAIL;
  }

  m_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
  if (!m_pD3D) {
    DbgLog((LOG_ERROR, 10, L"-> Failed to acquire IDirect3D9"));
    return E_FAIL;
  }

  int lAdapter = D3DADAPTER_DEFAULT;

  D3DADAPTER_IDENTIFIER9 d3dai = {0};
  m_pD3D->GetAdapterIdentifier(lAdapter, 0, &d3dai);

  const char *vendor = "Unknown";
  for (int i = 0; vendors[i].id != 0; i++) {
    if (vendors[i].id == d3dai.VendorId) {
      vendor = vendors[i].name;
      break;
    }
  }

  DbgLog((LOG_TRACE, 10, L"-> Running on adapter %d, %S, vendor 0x%04X(%S), device 0x%04X", lAdapter, d3dai.Description, d3dai.VendorId, vendor, d3dai.DeviceId));
  m_dwVendorId = d3dai.VendorId;
  m_dwDeviceId = d3dai.DeviceId;

  D3DPRESENT_PARAMETERS d3dpp;
  D3DDISPLAYMODE d3ddm;

  ZeroMemory(&d3dpp, sizeof(d3dpp));
  m_pD3D->GetAdapterDisplayMode(lAdapter, &d3ddm);

  d3dpp.Windowed               = TRUE;
  d3dpp.BackBufferWidth        = 640;
  d3dpp.BackBufferHeight       = 480;
  d3dpp.BackBufferCount        = 0;
  d3dpp.BackBufferFormat       = d3ddm.Format;
  d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;
  d3dpp.Flags                  = D3DPRESENTFLAG_VIDEO;

  hr = m_pD3D->CreateDevice(lAdapter, D3DDEVTYPE_HAL, GetShellWindow(), D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE, &d3dpp, &m_pD3DDev);
  if (FAILED(hr)) {
    DbgLog((LOG_TRACE, 10, L"-> Creation of device failed with hr: %X", hr));
    return E_FAIL;
  }

  hr = CreateD3DDeviceManager(m_pD3DDev, &m_pD3DResetToken, &m_pD3DDevMngr);
  if (FAILED(hr)) {
    DbgLog((LOG_TRACE, 10, L"-> Creation of Device manager failed with hr: %X", hr));
    return E_FAIL;
  }

  hr = SetD3DDeviceManager(m_pD3DDevMngr);
  if (FAILED(hr)) {
    DbgLog((LOG_TRACE, 10, L"-> SetD3DDeviceManager failed with hr: %X", hr));
    return E_FAIL;
  }

  return S_OK;
}
bool UIShowDeskBand(bool t)
{
	CLSID CLSID_OVDeskBand ={0x6d5d9154, 0xb557, 0x4509, {0x82, 0x9e, 0x94, 0xb8, 0xbf, 0x96, 0x2e, 0x5b}};
	static HRESULT  bandID=0;
	bool ret=false;
	int i =0;
	
	
	murmur("hIMEWND:%x, AncestorWND:%x, TopWindow:%x, ForegroundWindow:%x, ShellWindow:%x "
				,hIMEWnd, GetAncestor(hIMEWnd,GA_ROOTOWNER), GetTopWindow(NULL), GetForegroundWindow(), GetShellWindow());
	
	

	//CLSID CLSIDDeskBand = {0x46b3d3ef, 0x71a, 0x4b7e, {0x8a, 0xa2, 0xe5, 0x60, 0x81, 0xd, 0xab, 0x35}};
	
	// only for vista
	/*
	ITrayDeskBand * spTrayDeskBand=0; 
	if(SUCCEEDED(CoCreateInstance(CLSID_TrayDeskBand, NULL, CLSCTX_LOCAL_SERVER,
									IID_ITrayDeskBand, (void**)&spTrayDeskBand)))
	{
		if(t) spTrayDeskBand->ShowDeskBand(CLSID_OVDeskBand);
		else spTrayDeskBand->HideDeskBand(CLSID_OVDeskBand);
	}
	*/
	CComPtr <IUnknown>    spBandService;  
	if(!spBandSite) 
	{
		if(SUCCEEDED(spBandService.CoCreateInstance(CLSID_TrayBandSiteService,   NULL)))
		{
			//HWND aWnd = GetAncestor(hIMEWnd, GA_ROOTOWNER);
			//if(aWnd) BringWindowToTop(aWnd); 
			murmur("Create IBandsite interface succeed"); 
			spBandService->QueryInterface(&spBandSite);
		}
		else 
		{
			murmur("Create IBandsite interface failed");
			
			spBand = NULL;
			spBandSite = NULL;
			//WaitForSingleObject(NULL, 3000);
			//SendMessage(hIMEWnd, WM_IME_NOTIFY, IMN_OPENSTATUSWINDOW, 0);
		
		}
	}
	
	
	
	if(spBandSite && !spBand ) 
	{
		if(SUCCEEDED(CoCreateInstance(CLSID_OVDeskBand,   
				NULL,   CLSCTX_INPROC,   IID_IUnknown,   (void**)&spBand)))
		{
	
	//	CComPtr<IObjectWithSite>   spSite;  
	//    if(SUCCEEDED(spBand->QueryInterface(&spSite))   )   
	//	{
	//		spSite->SetSite(spBandSite);  
	//	}
	//	else spBand = NULL;
		}
		else spBand = NULL;
		
	}
	
    //if(SUCCEEDED(spBandService.CoCreateInstance(CLSID_TrayBandSiteService,   NULL))   
	// 				  &&   SUCCEEDED(spBandService->QueryInterface(&spBandSite))   )  
	if( spBand && spBandSite)
    {  			
        	if(t) 
			{
			if(!((int)bandID >0))
			  {
				bandID = spBandSite->AddBand(spBand);  
				murmur("\tBandID:%d",bandID);
				if( (int)bandID >0 ) 
				{
					murmur("Create deskband succeeded."); 

					//spBand  =   NULL;  
					//spBandSite   =   NULL;   
					ret = true;  
				}
				else
				{
					murmur("Create deskband failed."); 
					spBand->ShowDW(0);  
					spBand  =   NULL; 
					spBandSite   =   NULL;   
					bandID =0; 
				}
			  }
			else
			{
				murmur("\tBandID:%d",bandID);
				murmur("Deskband created."); 
			}


				
			}
			else if((int)bandID >0)
			{
				
				
				//HWND aWnd = GetAncestor(hIMEWnd, GA_ROOTOWNER);
				//if(aWnd) BringWindowToTop(aWnd);
			    if(SUCCEEDED( spBandSite->RemoveBand(bandID))) 
				{
					murmur("\tBandID:%d",bandID);
					murmur("Remove deskband succeeded.");  
					
					spBand  =   NULL; 
					spBandSite   =   NULL;   
					bandID =0;
					
					//CoUninitialize();
					ret = true;
				}
				else
				{ 
					murmur("Remove deskband failed.");
					//spBand->CloseDW(0); 
					//spBand=NULL;
					//spBandSite = NULL;   
					//bandID =0;
					
					//HANDLE hEvent = CreateEvent(NULL,FALSE,FALSE,_T("OVE")); 
					//WaitForSingleObject(hEvent, 500);
					 
					//SendMessage(hIMEWnd, WM_IME_NOTIFY, IMN_CLOSESTATUSWINDOW, 0);
				}
				
			}
			else
			{
					murmur("Deskband was not created.");
					//spBand->CloseDW(0); 
					spBand=NULL;
					spBandSite = NULL;   
				
			}			  
            
                    
         
    }              
	

	//}
	//while(!ret && i++<3);
	murmur("::hIMEWND:%x, AncestorWND:%x, TopWindow:%x, ForegroundWindow:%x, ShellWindow:%x "
				,hIMEWnd, GetAncestor(hIMEWnd,GA_ROOTOWNER), GetTopWindow(NULL), GetForegroundWindow(), GetShellWindow());

    
	return ret;
	
}
Example #29
0
static int dxva2_alloc(AVCodecContext *s)
{
    HwAccelContext  *hac = s->opaque;
    DXVA2Context *ctx;
    pDirect3DCreate9      *createD3D = NULL;
    pCreateDeviceManager9 *createDeviceManager = NULL;
    HRESULT hr;
    D3DPRESENT_PARAMETERS d3dpp = {0};
    D3DDISPLAYMODE        d3ddm;
    unsigned resetToken = 0;
    UINT adapter = D3DADAPTER_DEFAULT;

    ctx = av_mallocz(sizeof(*ctx));
    if (!ctx)
        return AVERROR(ENOMEM);

    ctx->deviceHandle = INVALID_HANDLE_VALUE;

    hac->hwaccel_ctx           = ctx;
    hac->hwaccel_uninit        = dxva2_uninit;
    hac->hwaccel_get_buffer    = dxva2_get_buffer;
    hac->hwaccel_retrieve_data = dxva2_retrieve_data;

    ctx->d3dlib = LoadLibrary("d3d9.dll");
    if (!ctx->d3dlib) {
        av_log(NULL, loglevel, "Failed to load D3D9 library\n");
        goto fail;
    }
    ctx->dxva2lib = LoadLibrary("dxva2.dll");
    if (!ctx->dxva2lib) {
        av_log(NULL, loglevel, "Failed to load DXVA2 library\n");
        goto fail;
    }

    createD3D = (pDirect3DCreate9 *)GetProcAddress(ctx->d3dlib, "Direct3DCreate9");
    if (!createD3D) {
        av_log(NULL, loglevel, "Failed to locate Direct3DCreate9\n");
        goto fail;
    }
    createDeviceManager = (pCreateDeviceManager9 *)GetProcAddress(ctx->dxva2lib, "DXVA2CreateDirect3DDeviceManager9");
    if (!createDeviceManager) {
        av_log(NULL, loglevel, "Failed to locate DXVA2CreateDirect3DDeviceManager9\n");
        goto fail;
    }

    ctx->d3d9 = createD3D(D3D_SDK_VERSION);
    if (!ctx->d3d9) {
        av_log(NULL, loglevel, "Failed to create IDirect3D object\n");
        goto fail;
    }

    if (hac->hwaccel_device) {
        adapter = atoi(hac->hwaccel_device);
        av_log(NULL, AV_LOG_INFO, "Using HWAccel device %d\n", adapter);
    }

    IDirect3D9_GetAdapterDisplayMode(ctx->d3d9, adapter, &d3ddm);
    d3dpp.Windowed         = TRUE;
    d3dpp.BackBufferWidth  = 640;
    d3dpp.BackBufferHeight = 480;
    d3dpp.BackBufferCount  = 0;
    d3dpp.BackBufferFormat = d3ddm.Format;
    d3dpp.SwapEffect       = D3DSWAPEFFECT_DISCARD;
    d3dpp.Flags            = D3DPRESENTFLAG_VIDEO;

    hr = IDirect3D9_CreateDevice(ctx->d3d9, adapter, D3DDEVTYPE_HAL, GetShellWindow(),
                                 D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
                                 &d3dpp, &ctx->d3d9device);
    if (FAILED(hr)) {
        av_log(NULL, loglevel, "Failed to create Direct3D device\n");
        goto fail;
    }

    hr = createDeviceManager(&resetToken, &ctx->d3d9devmgr);
    if (FAILED(hr)) {
        av_log(NULL, loglevel, "Failed to create Direct3D device manager\n");
        goto fail;
    }

    hr = IDirect3DDeviceManager9_ResetDevice(ctx->d3d9devmgr, ctx->d3d9device, resetToken);
    if (FAILED(hr)) {
        av_log(NULL, loglevel, "Failed to bind Direct3D device to device manager\n");
        goto fail;
    }

    hr = IDirect3DDeviceManager9_OpenDeviceHandle(ctx->d3d9devmgr, &ctx->deviceHandle);
    if (FAILED(hr)) {
        av_log(NULL, loglevel, "Failed to open device handle\n");
        goto fail;
    }

    hr = IDirect3DDeviceManager9_GetVideoService(ctx->d3d9devmgr, ctx->deviceHandle, &IID_IDirectXVideoDecoderService, (void **)&ctx->decoder_service);
    if (FAILED(hr)) {
        av_log(NULL, loglevel, "Failed to create IDirectXVideoDecoderService\n");
        goto fail;
    }

    ctx->tmp_frame = av_frame_alloc();
    if (!ctx->tmp_frame)
        goto fail;

    s->hwaccel_context = av_mallocz(sizeof(struct dxva_context));
    if (!s->hwaccel_context)
        goto fail;

    return 0;
fail:
    dxva2_uninit(s);
    return AVERROR(EINVAL);
}
Example #30
0
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    // Updates only for supported platforms
    if (!supported)
        fatalError(tr("The qTox updater is not supported on this platform."));

#ifdef Q_OS_WIN
    // Get a primary unelevated token of the actual user
    hPrimaryToken = nullptr;
    HANDLE hShellProcess = nullptr, hShellProcessToken = nullptr;
    const DWORD dwTokenRights = TOKEN_QUERY | TOKEN_IMPERSONATE | TOKEN_ASSIGN_PRIMARY
                                | TOKEN_DUPLICATE | TOKEN_ADJUST_DEFAULT | TOKEN_ADJUST_SESSIONID;
    DWORD dwPID = 0;
    HWND hwnd = nullptr;
    DWORD dwLastErr = 0;

    // Enable SeIncreaseQuotaPrivilege
    HANDLE hProcessToken = NULL;
    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hProcessToken))
        goto unelevateFail;
    TOKEN_PRIVILEGES tkp;
    tkp.PrivilegeCount = 1;
    LookupPrivilegeValueW(NULL, SE_INCREASE_QUOTA_NAME, &tkp.Privileges[0].Luid);
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    AdjustTokenPrivileges(hProcessToken, FALSE, &tkp, 0, NULL, NULL);
    dwLastErr = GetLastError();
    CloseHandle(hProcessToken);
    if (ERROR_SUCCESS != dwLastErr)
        goto unelevateFail;

    // Get a primary copy of the desktop shell's token,
    // we're assuming the shell is running as the actual user
    hwnd = GetShellWindow();
    if (!hwnd)
        goto unelevateFail;
    GetWindowThreadProcessId(hwnd, &dwPID);
    if (!dwPID)
        goto unelevateFail;
    hShellProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwPID);
    if (!hShellProcess)
        goto unelevateFail;
    if (!OpenProcessToken(hShellProcess, TOKEN_DUPLICATE, &hShellProcessToken))
        goto unelevateFail;

    // Duplicate the shell's process token to get a primary token.
    // Based on experimentation, this is the minimal set of rights required for CreateProcessWithTokenW (contrary to current documentation).
    if (!DuplicateTokenEx(hShellProcessToken, dwTokenRights, NULL, SecurityImpersonation, TokenPrimary, &hPrimaryToken))
        goto unelevateFail;

    qDebug() << "Unelevated primary access token acquired";
    goto unelevateCleanup;
unelevateFail:
    qWarning() << "Unelevate failed, couldn't get access token";
unelevateCleanup:
    CloseHandle(hShellProcessToken);
    CloseHandle(hShellProcess);
#endif

    QMetaObject::invokeMethod(this, "update", Qt::QueuedConnection);
}