Hi, there,
Any one could help me to have a look at this which acted as below:
Environment:
>>1. win7 32bits.
>>2. UAC ON
I prepared a little test program(called SwitchDesktop) which is do and only do switch default desktop to another desktop (e.g. mytest default desktop.)
Things seems very dramatically what happenned next.
1. UAC OFF, switched to another desktop, everything works fine and perfect nice.
2. UAC ON, switched to another desktop, everything works fine except explorer could not start up as normal, and even not as the default desktop, which works perfect well on winxp. and everything works perfect nice when I switched back to default desktop.
3. Right Clicked and choose run as administrator, everything works fine and ok.
well, I tried sysinternalsuits's desktops.exe, that works fine no matter UAC on or off, IE could start up as normally as the default desktop.
So, I wonder how does Desktops.exe realise switch desktop?
I checked security, SwitchDesktop performs the same with Desktops. I was thought that things may goes wrong frome the process of explorer.exe for that which is the parent process of iexplorer.exe. but I got confused after I did not start explorer.exe and switched desktop only with uac off and start iexplorer.exe with taskmgr.exe --> file -> run->iexplorer.exe
here's my code:
#include "stdafx.h"
#include "resource.h"
#include "ShellApi.h"
#include <string.h>
#include <stdio.h>
#include <string.h>
HINSTANCE hInst = NULL;
HDESK hDesktopCurrent;
HDESK hDesktopLlx;
HDESK hOriginalInput;
DWORD g_pid = 0;
LONG APIENTRY WndProc(
HWND hWnd,
UINT message, WPARAM wParam, LPARAM lParam) {
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId) {
case IDM_ABOUT:
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
RECT rt;
GetClientRect(hWnd, &rt);
EndPaint(hWnd, &ps);
break;
case WM_LBUTTONDOWN:
break;
case WM_HOTKEY:
if(7777 == wParam)
{
PostQuitMessage(0);
}
else if(7778 == wParam)
{
SwitchDesktop(hOriginalInput);
}
else if(7779 == wParam)
{
SwitchDesktop(hOriginalInput);
}
break;
case WM_QUIT:
case WM_DESTROY:
SwitchDesktop(hOriginalInput);
return DefWindowProc(hWnd, message, wParam, lParam);
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
void StartMyExplore(void)
{
STARTUPINFO sui; PROCESS_INFORMATION pi; SECURITY_ATTRIBUTES attr;
ZeroMemory ((PVOID)&sui, sizeof(sui));
sui.cb = sizeof (sui);
sui.lpDesktop = _T("my_new_desktop_1");
attr.nLength = sizeof(attr);
attr.lpSecurityDescriptor = NULL;
attr.bInheritHandle = true;
CreateProcess (NULL, "C:\\Windows\\Explorer.exe", &attr, NULL, true, 0,
NULL, NULL, &sui, &pi); }
int CALLBACK WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASS wc;
SECURITY_ATTRIBUTES attr;
wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (NULL, "IDI_SETTHREADDESKTOP");
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "newdesktopclass";
if(!RegisterClass(&wc)) {
return TRUE;
}
hDesktopCurrent = NULL;
hOriginalInput = NULL;
hDesktopCurrent = GetThreadDesktop(GetCurrentThreadId());
hOriginalInput = OpenInputDesktop(0, FALSE, DESKTOP_SWITCHDESKTOP);
hDesktopLlx = NULL;
attr.nLength = sizeof(attr);
attr.lpSecurityDescriptor = NULL;
attr.bInheritHandle = true;
hDesktopLlx = CreateDesktopEx(
"my_new_desktop_1",
NULL,
NULL,
0,
GENERIC_ALL,
&attr,
0,
NULL);
if(hDesktopLlx == NULL) {
MessageBox(NULL, "CreateDesktopEx failed", NULL, MB_OK);
return 0;
}
SwitchDesktop(hDesktopLlx);
SetThreadDesktop(hDesktopLlx);
HWND hWnd = NULL;
hWnd = CreateWindow ("newdesktopclass",
"hello, new window!",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
NULL,
NULL,
hInstance,
NULL
);
if(NULL == hWnd) {
return TRUE;
}
if(!RegisterHotKey(hWnd, 7777, MOD_CONTROL, 'Q'))
{ return TRUE;
}
if(!RegisterHotKey(hWnd, 7778, MOD_CONTROL | MOD_SHIFT, 'Q'))
{ return TRUE;
}
if(!RegisterHotKey(hWnd, 7779, MOD_CONTROL | MOD_SHIFT, 'W'))
{ return TRUE;
}
StartMyExplore();
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg); DispatchMessage(&msg); }
SwitchDesktop(hOriginalInput);
SetThreadDesktop(hDesktopCurrent);
return TRUE;
}