2

I am trying to start Firefox in new desktop using CreateDesktop() Windows function but I am having problems with Flash when Flash's Protected Mode is enabled.

Flash works perfectly when I start Firefox in the default desktop, but Firefox hangs in the new desktop because Flash never starts.

Disabling Flash's Protected Mode solves this issue but I want to be able to run this without having to disable Flash's Protected Mode.

It might be similar to this problem: CreateDesktop() with vista and UAC on (C, windows)

I am trying to read the security information from the default desktop and set it to the new one and I get 'permission denied'. However I still do not know if this is the right approach.

Does anyone know how to start a process in a desktop created with CreateDesktop() Windows function so that Flash can run with Protected Mode enabled?

Is there a way to set the security info of my new desktop without getting the info from the old one?

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682124%28v=vs.85%29.aspx

This is the code I use to start Firefox in a new desktop:

// createDesktopTESTWin32Project.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "createDesktopTESTWin32Project.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;                                // current instance
TCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name

// Forward declarations of functions included in this code module:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);

HDESK hDesktopThreadOld;
HDESK hDesktopInputOld;
HDESK hNewDesktop;

void ClearUp()
{
    // Make sure to get back to the original desktop
    if(hDesktopInputOld != 0)
    {
        SwitchDesktop(hDesktopInputOld);
        hDesktopInputOld = 0;
    }
    if(hDesktopThreadOld != 0)
    {
        SetThreadDesktop(hDesktopThreadOld);
        hDesktopThreadOld = 0;
    }
    if(hNewDesktop != 0)
    {
        CloseDesktop(hNewDesktop);
        hNewDesktop = 0;
    }
}

void StartProcess()
{
    STARTUPINFO si = {0};
    PROCESS_INFORMATION pi;

    // Set the desktop to run on in the STARTUPINFO structure
    si.cb = sizeof(si);
    si.lpDesktop = _T("MYNEWDESKTOP");

    TCHAR ourPath[MAX_PATH] = _T("C:\\Program Files (x86)\\Mozilla firefox\\firefox.exe http://www.adobe.com/products/flashplayer.html");

    //BOOL retVal = CreateProcess(NULL, ourPath, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi);
    BOOL retVal = CreateProcess(NULL, ourPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);

    if(!retVal)
    {
        _tprintf(_T("Failed to create new process !!\n\n"));
        ClearUp();
    } else {
        // Wait until the process has finished
        //WaitForSingleObject(pi.hProcess, INFINITE);

        // Kill after 2 minutes for now as a test since it hangs
        WaitForSingleObject(pi.hProcess, 120000);

        // Terminate program
        TerminateThread(pi.hThread, 0);
        TerminateProcess(pi.hProcess, 0);

        // Clean
        CloseHandle(pi.hProcess);
        CloseHandle(pi.hThread);
    }
}

void CreateNewDesktop()
{
    hDesktopThreadOld = GetThreadDesktop(GetCurrentThreadId());
    hDesktopInputOld = OpenInputDesktop(0, false, DESKTOP_SWITCHDESKTOP);
    hNewDesktop = CreateDesktop(_T("MYNEWDESKTOP"), 0, 0, 0, GENERIC_ALL, NULL);

    if(!hNewDesktop)
    {
        _tprintf(_T("Failed to create new desktop !!\n\n"));
    } else {
        SetThreadDesktop(hNewDesktop);
        SwitchDesktop(hNewDesktop);
    }
}

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
    CreateNewDesktop();
    StartProcess();
    ClearUp();
    return 0;
}
Community
  • 1
  • 1
sleon
  • 51
  • 7

0 Answers0