2

我正在尝试使用 CreateDesktop() Windows 函数在新桌面中启动 Firefox,但是在启用 Flash 的保护模式时我遇到了 Flash 问题。

当我在默认桌面上启动 Firefox 时,Flash 可以完美运行,但 Firefox 在新桌面上挂起,因为 Flash 永远不会启动。

禁用 Flash 的保护模式可以解决这个问题,但我希望能够运行它而不必禁用 Flash 的保护模式。

它可能类似于这个问题: CreateDesktop() with vista and UAC on (C, windows)

我正在尝试从默认桌面读取安全信息并将其设置为新桌面,但我得到“权限被拒绝”。但是我仍然不知道这是否是正确的方法。

有谁知道如何在使用 CreateDesktop() Windows 函数创建的桌面中启动一个进程,以便 Flash 可以在启用保护模式的情况下运行?

有没有办法在不从旧桌面获取信息的情况下设置新桌面的安全信息?

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

这是我用来在新桌面上启动 Firefox 的代码:

// 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;
}
4

0 回答 0