Solved

Windows Desktop API - windows shortcuts on the correct Desktop ?

Posted on 2007-03-23
9
1,176 Views
Last Modified: 2013-12-04
Hello,
I am writing a small application in C++ based on the Desktop API (CreateDesktop / OpenDesktop / SwitchDesktop)
I create a secondary desktop and i spawn explorer.exe into it.

Each time I use a windows shortcut from this secondary desktop (like WIN + E / CTRL + ALT + SUPP)
it creates the associated window into the first / primary default desktop.

How to make the windows shortcuts works correctly ?
What are the differents solutions to solve this problem ?

I don't like catching all keyboard combinaisons myself.

0
Comment
Question by:nrigaud
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 18778569
Do you want to disable windows hot keys while you are on your 'private desktop'/ new desktop created by CreateDesktop() API?
Best Regards,
DeepuAbrahamK
0
 

Author Comment

by:nrigaud
ID: 18778603
No, i want to make them work on any Desktop.
thx
0
 
LVL 86

Expert Comment

by:jkr
ID: 18780169
Check out the article at http://www.codeguru.com/Cpp/W-P/system/misc/article.php/c5695 ("Creating and Switching to Different Desktops") - the scoop is to specify the desktop name in the STARTUP_INFO struct when launching a process, e.g.

                  SECURITY_ATTRIBUTES saDesktop = { sizeof(saDesktop), NULL, TRUE };
                  hDesk =
                  CreateDesktop(szDesktop,
                        NULL,
                        NULL,
                        NULL,
                        DESKTOP_ALL_ACCESS,
                        &saDesktop);

                  STARTUPINFO startInfo1 = { 0 };
                  startInfo1.cb = sizeof(startInfo1);
                  startInfo1.lpDesktop = szDesktop;
                  PROCESS_INFORMATION psInfo1 = { NULL };

                  bRet =
                  CreateProcess(NULL,
                        szCommandLine,
                        NULL, //process security descriptor
                        NULL, //thread security descriptor
                        TRUE, //inherit handles
                        NORMAL_PRIORITY_CLASS, //creation flags
                        NULL, //environment block - use current
                        (LPCTSTR)szStartDir, //startup directory
                        &startInfo1,
                        &psInfo1);

                  if(bRet==FALSE)
                  {
                        Error();
                  }

                  if(hDesk!=NULL)
                  {
                        if(FALSE == CloseDesktop(hDesk))
                        {
                              Error();
                        }
                  }
                  return bRet;
            }

Also of interest: http://www.codeproject.com/system/RunUser.asp ("GUI-Based RunAsEx") which takes the whole thing one step further.
0
 

Author Comment

by:nrigaud
ID: 18780302
I know how to do that.

Am not creating these processes, the system is (in response to windows default hotkeys).
So i can' t apply this method.



0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 86

Expert Comment

by:jkr
ID: 18780863
Hmmm, rethinking that: When you launch a shell link, the shell calls 'ShellExecute()' or it's 'Ex' successor. Both do not support any parameters to specify a desktop, so when finally 'CreateProcess()' is called it uses a NULL parameter for 'lpDesktop', which in turn makes the process show up un the default desktop...
0
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 18784736
Don't think whether you can do this unless you create a different hotkeys to hanlde this inside your private desktop ! Is that a valid option to you?
Best Regards,
DeepuAbrahamK
0
 

Author Comment

by:nrigaud
ID: 18791187
I don't want different hotkeys.
0
 
LVL 10

Accepted Solution

by:
pjasnos earned 500 total points
ID: 18952302
It seems to me that it would be relatively hard to do, as hotkeys are systemwide (according to Microsoft's documentation, in reality they are winstation-wide):

http://msdn2.microsoft.com/en-us/library/ms646309.aspx

(Ctrl+Alt+Delete is also registered using RegisterHotKey inside winlogon process, there is no magic connected with it, as microsoft docs claim). This means that when you spawn another explorer.exe, the first one has not freed the hotkeys (or terminated; termination closes the window with which the HotKey is associated), hence the second one would just silently fail to register them.

Your options:
-Guess/reverse engineer/auto-obtain the id of the hotkeys of explorer exe (a simple RegisterHotKey proxy dll injected into the newly spawned explorer and preferably any other processes on the new desktop) and then Unregister/reregister them when performing desktop switching.

-write a system-wide window message filtering hook and reroute WM_HOTKEYs to the apropriate windows (probably by using a proxy dll like in the above case to determine the proper hwnd; i don't know whether the window accepting hotkeys in explorer has specific class/window caption, if it does you may possibly avoid the need to use it, at least for explerer)

-{[mad scientist solution]} you could possibly do this without dll hassle through sessions or window stations, but granting input to something other than Winsta0 is veeeery tough and you would certainly need SE_TCB or probably inject something into winlogon and messup with winsta.dll undocumented apis
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now