Solved

Windows Desktop API - windows shortcuts on the correct Desktop ?

Posted on 2007-03-23
9
1,179 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

911 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

16 Experts available now in Live!

Get 1:1 Help Now