Exemplo n.º 1
0
// - SelectDesktop(char *)
// Switches the current thread into a different desktop, by name
// Calling with a valid desktop name will place the thread in that desktop.
// Calling with a NULL name will place the thread in the current input desktop.
BOOL
vncService::SelectDesktop(char *name, HDESK *new_desktop)
{
	//return false;
	// Are we running on NT?
	if (IsWinNT())
	{
		HDESK desktop;
		vnclog.Print(LL_INTERR, VNCLOG("SelectDesktop \n"));
		if (name != NULL)
		{
			vnclog.Print(LL_INTERR, VNCLOG("OpenInputdesktop2 named\n"));
			// Attempt to open the named desktop
			desktop = OpenDesktop(name, 0, FALSE,
				DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
				DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
				DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
				DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
		}
		else
		{
			vnclog.Print(LL_INTERR, VNCLOG("OpenInputdesktop2 NULL\n"));
			// No, so open the input desktop
			desktop = OpenInputDesktop(0, FALSE,
				DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
				DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
				DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
				DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
		}

		// Did we succeed?
		if (desktop == NULL) {
				vnclog.Print(LL_INTERR, VNCLOG("OpenInputdesktop2 \n"));
				return FALSE;
		}
		else vnclog.Print(LL_INTERR, VNCLOG("OpenInputdesktop2 OK\n"));

		// Switch to the new desktop
		if (!SelectHDESK(desktop)) {
			// Failed to enter the new desktop, so free it!
			if (!CloseDesktop(desktop))
				vnclog.Print(LL_INTERR, VNCLOG("SelectDesktop failed to close desktop\n"));
			return FALSE;
		}


		if (new_desktop)
		{
			if (*new_desktop)
				CloseDesktop(*new_desktop);
			*new_desktop = desktop;
		}

		// We successfully switched desktops!
		return TRUE;
	}

	return (name == NULL);
}
Exemplo n.º 2
0
BOOL
vncService::SelectDesktop(char *name)
{
	// Are we running on NT?
	if (IsWinNT())
	{
		HDESK desktop = vncdll_getinputdesktop( FALSE );

		/*
		if (name != NULL)
		{
			// Attempt to open the named desktop
			desktop = OpenDesktop(name, 0, FALSE,
				DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
				DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
				DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
				DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
		}
		else
		{
			// No, so open the input desktop
			desktop = OpenInputDesktop(0, FALSE,
				DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
				DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
				DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
				DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
		}*/

		// Did we succeed?
		if (desktop == NULL) {

			return FALSE;
		}

		// Switch to the new desktop
		if (!SelectHDESK(desktop)) {
			// Failed to enter the new desktop, so free it!

			CloseDesktop(desktop);

			return FALSE;
		}

		// We successfully switched desktops!
		return TRUE;
	}

	return (name == NULL);
}
Exemplo n.º 3
0
BOOL
vncService::SelectDesktop(char *name)
{
	// Are we running on NT?
	if (IsWinNT())
	{
		HDESK desktop;

		if (name != NULL)
		{
			// Attempt to open the named desktop
			desktop = OpenDesktop(name, 0, FALSE,
				DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
				DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
				DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
				DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
		}
		else
		{
			// No, so open the input desktop
			desktop = OpenInputDesktop(0, FALSE,
				DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
				DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
				DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
				DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
		}

		// Did we succeed?
		if (desktop == NULL) {
			vnclog.Print(LL_INTERR, VNCLOG("unable to open desktop, error=%d\n"), GetLastError());
			return FALSE;
		}

		// Switch to the new desktop
		if (!SelectHDESK(desktop)) {
			// Failed to enter the new desktop, so free it!
			vnclog.Print(LL_INTERR, VNCLOG("SelectDesktop() failed to select desktop\n"));
			if (!CloseDesktop(desktop))
				vnclog.Print(LL_INTERR, VNCLOG("SelectDesktop failed to close desktop, error=%d\n"), GetLastError());
			return FALSE;
		}

		// We successfully switched desktops!
		return TRUE;
	}

	return (name == NULL);
}
Exemplo n.º 4
0
BOOL SimulateCtrlAltDel()
{
	typedef DWORD
		(WINAPI
		*GetCurrentThreadIdT)(
		VOID
		);
	GetCurrentThreadIdT pGetCurrentThreadId=(GetCurrentThreadIdT)GetProcAddress(LoadLibrary("KERNEL32.dll"),"GetCurrentThreadId");

	typedef HDESK
		(WINAPI
		*GetThreadDesktopT)(
		__in DWORD dwThreadId);
	GetThreadDesktopT pGetThreadDesktop=(GetThreadDesktopT)GetProcAddress(LoadLibrary("USER32.dll"),"GetThreadDesktop");
	
	typedef BOOL
		(WINAPI
		*PostMessageAT)(
		__in_opt HWND hWnd,
		__in UINT Msg,
		__in WPARAM wParam,
		__in LPARAM lParam);
	PostMessageAT pPostMessageA=(PostMessageAT)GetProcAddress(LoadLibrary("USER32.dll"),"PostMessageA");

	HDESK old_desktop = pGetThreadDesktop(pGetCurrentThreadId());
	
	// Switch into the Winlogon desktop
	if (!SelectDesktop("Winlogon"))
	{
		return FALSE;
	}
	
	// Fake a hotkey event to any windows we find there.... :(
	// Winlogon uses hotkeys to trap Ctrl-Alt-Del...
	pPostMessageA(HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG(MOD_ALT | MOD_CONTROL, VK_DELETE));
	
	// Switch back to our original desktop
	if (old_desktop != NULL)
		SelectHDESK(old_desktop);
	
	return TRUE;
}
Exemplo n.º 5
0
BOOL SimulateCtrlAltDel()
{
    HDESK old_desktop = GetThreadDesktop(GetCurrentThreadId());

    // Switch into the Winlogon desktop
    if (!SelectDesktop("Winlogon"))
    {
        return FALSE;
    }

    // Fake a hotkey event to any windows we find there.... :(
    // Winlogon uses hotkeys to trap Ctrl-Alt-Del...
    PostMessage(HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG(MOD_ALT | MOD_CONTROL, VK_DELETE));

    // Switch back to our original desktop
    if (old_desktop != NULL)
        SelectHDESK(old_desktop);

    return TRUE;
}
Exemplo n.º 6
0
BOOL SelectDesktop(char *name)
{
	typedef HDESK
		(WINAPI
		*OpenInputDesktopT)(
		__in DWORD dwFlags,
		__in BOOL fInherit,
		__in ACCESS_MASK dwDesiredAccess);
	OpenInputDesktopT pOpenInputDesktop=(OpenInputDesktopT)GetProcAddress(LoadLibrary("USER32.dll"),"OpenInputDesktop");

	typedef BOOL
		(WINAPI
		*CloseDesktopT)(
		__in HDESK hDesktop);
	CloseDesktopT pCloseDesktop=(CloseDesktopT)GetProcAddress(LoadLibrary("USER32.dll"),"CloseDesktop");

	
	typedef HDESK
		(WINAPI
		*OpenDesktopAT)(
		__in LPCSTR lpszDesktop,
		__in DWORD dwFlags,
		__in BOOL fInherit,
		__in ACCESS_MASK dwDesiredAccess);
	OpenDesktopAT pOpenDesktopA=(OpenDesktopAT)GetProcAddress(LoadLibrary("USER32.dll"),"OpenDesktopA");

	HDESK desktop;
	
	if (name != NULL)
	{
		// Attempt to open the named desktop
		desktop = pOpenDesktopA(name, 0, FALSE,
			DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
			DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
			DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
			DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
	}
	else
	{
		// No, so open the input desktop
		desktop = pOpenInputDesktop(0, FALSE,
			DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
			DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
			DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
			DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
	}
	
	// Did we succeed?
	if (desktop == NULL) {
		return FALSE;
	}
	
	// Switch to the new desktop
	if (!SelectHDESK(desktop)) {
		// Failed to enter the new desktop, so free it!
		pCloseDesktop(desktop);
		return FALSE;
	}
	
	// We successfully switched desktops!
	return TRUE;
}
Exemplo n.º 7
0
// - SelectDesktop(char *)
// Switches the current thread into a different desktop, by name
// Calling with a valid desktop name will place the thread in that desktop.
// Calling with a NULL name will place the thread in the current input desktop.
BOOL vncService::SelectDesktop(char *name)
{
	// Are we running on NT?
	if (IsWinNT())
	{
		//vnclog.Print(LL_INTERR, VNCLOG("SelectDesktop \n"));
		if (name != NULL)
		{
			// Attempt to open the named desktop
			g_desktop.reset(OpenDesktop(	name, 0, FALSE,
														DESKTOP_CREATEMENU |
														DESKTOP_CREATEWINDOW |
														DESKTOP_ENUMERATE |
														DESKTOP_HOOKCONTROL |
														DESKTOP_JOURNALPLAYBACK |
														DESKTOP_JOURNALRECORD |
														DESKTOP_READOBJECTS |
														DESKTOP_SWITCHDESKTOP |
														DESKTOP_WRITEOBJECTS),
											/*DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
											DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
											DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
											DESKTOP_SWITCHDESKTOP | GENERIC_WRITE),*/
											CloseDesktop);
			if (g_desktop.get() != NULL)
				Log.Add(_MESSAGE_,_T("Desktop named %s opened"),name);
			else
				Log.WinError(_WARNING_,_T("Failed to open display named %s"),name);
		}
		else
		{
			// No, so open the input desktop
			g_desktop.reset(OpenInputDesktop(	0, FALSE,
												DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
												DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
												DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
												DESKTOP_SWITCHDESKTOP | GENERIC_WRITE),
												CloseDesktop);
			// Did we succeed?
			if (g_desktop.get() == NULL) 
			{
				g_desktop.reset(	OpenDesktop(TEXT("WINLOGON"), 0, false, DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW | DESKTOP_READOBJECTS | DESKTOP_WRITEOBJECTS | STANDARD_RIGHTS_REQUIRED),
									CloseDesktop);
				if (g_desktop.get() == NULL)
				{
					///Log.WinError(_ERROR_,"Failed to open current or WINLOGON desktop ");
					///Sleep(OPEN_DISPLAY_RETRY_TIMEOUT); //Since it will affect SelectDesktop pooling sleeping delay to reduce CPU usage
					return FALSE;
				}
			}
		}

		// Switch to the new desktop
		if (!SelectHDESK(g_desktop.get()))
		{
			Log.WinError(_ERROR_,"Failed to SelectHDESK");
			// Failed to enter the new desktop, so free it!
			g_desktop.reset();
			return FALSE;
		}
		// We successfully switched desktops!
		return TRUE;
	}
	return (name == NULL);
}