Click here to Skip to main content
11,790,946 members (64,325 online)
Click here to Skip to main content

Virtual Desktop: A Simple Desktop Management Tool

, 25 Jul 2008 CPOL 135.9K 8.2K 137
Rate this:
Please Sign up or sign in to vote.
This article gives you an overview of Windows Station, Windows Desktop and how to work with them. It also has a sample application (Virtual Desktop) demonstrating multiple desktop management.



A few months ago, one of my colleagues was using a tool that was managing multiple desktops. I was wondering how the tool could manage multiple desktops. I thought it would be just hiding-and-displaying the application windows for different desktops when a user switches between them. As a matter of curiosity, I started studying multiple desktops and ended up with this article.

As I went through the details, I found that I was wrong in thinking that the tool was just hiding-and-displaying the application windows for different desktops. Even the thought that the "Desktop" we see is just a directory was wrong. Let's see how it works.

Window Station and Window Desktop

Actually Windows uses Window Station and Desktop architecture to provide additional security. For the time being, we can refer to "Desktop" as a logical display surface, which contains User Interface Objects (GDI objects) and User Objects. A Window Station is a secure kernel object which contains a clipboard, an atom table, and one or more desktop objects. There exists a default window station "WinSta0", an interactive window station. "WinSta0" is the only interactive window station that can display a user interface or receive user input. All other window stations are non-interactive. By default, there exist three Desktops in an interactive window station : Default, WinLogon and ScreenSaver.

A Desktop is also a secure kernel object. When a new desktop is created, it is associated with the current window station of the calling process. There will always be only one desktop visible (Active) and ready to receive user inputs, provided the desktop is associated with an interactive window station i.e. WinSta0. This active desktop is called the Input Desktop.

As I specified, there exist three desktops in an interactive window station: Default, WinLogon and ScreenSaver. The screen prompting to press ALT + CTL + DEL to login is the WinLogon desktop. Whenever the user logs in, the Default desktop is created and made visible. This "Default" is the default active desktop for any logged in user. When you press ALT + CTL + DEL, you'll be switched back again to the WinLogon desktop. The ScreenSaver desktop will be made visible whenever the screen saver gets activated. As these desktop names are case-insensitive, there could be only one desktop of a specific name in a window station. But a desktop name can be repeated in different window stations. The purpose behind Window Station and Desktop objects is to provide top level isolation between processes.

About the Virtual Desktop (A Sample Application)

The Virtual Desktop Tool helps you to create and switch between different desktops. It even gives you an illusion of switching the application from one desktop to another. But this isn't true as any running application cannot be moved from one desktop to other. As I said, it's just an illusion. The application will be closed in the current desktop and will be launched on the specified desktop. This may cause loss of any unsaved data of the application and may not persist the state as it will be restarted.

The application is using hooks to display "Move To" menu options in the applications Control Panel (System Menu). For more details about the hooks, I would refer this article. I will give you an overview of different APIs used and classes built in the application. Rest of the code in the application is self explanatory and (what I think is) well documented.

Different APIs Used and Classes Built


It retrieves the handle to the current Window Station of the calling process. The retrieved handle is used to enumerate all the desktops of the window station.


It creates a new Desktop with the specified name. This newly created desktop will be associated with the Window Station of the calling process and will be assigned to the calling thread.


It opens the specified Desktop. The handle returned by this function is used to switch between desktops.


It closes an open handle to Desktop.


This makes the specified Desktop visible and ready to receive user inputs (i.e. makes it Active).


It retrieves the handle to the Desktop associated with the specified thread.


It gives information about the Window Station and Desktop Objects.

The application has a class called CDesktopManager, in which all the desktop related activities are wrapped up. The application solution has a DLL Project, in which all the windows hook functionalities are wrapped up. This Event Hooker DLL is responsible for inserting menu options into the System Menu of the other applications.

Points of Interest

When we create a new desktop and switch to it, it shows nothing. The desktop will be blank(with just a wallpaper visible) -- that's because no process is running on that desktop. So, to avoid that, I launch an Explorer shell whenever I create a new desktop. I think I could add a feature to launch a new process/application on a specified desktop. And so I did in the current update. I have a few more features in mind. I'll keep updating whenever I complete them.

Revision History

  • 17 Nov 2007 : Initial release
  • 27 Dec 2007 : The application was exiting once it switches the desktop. It wasn't programmed to stay in memory any longer after desktop switch. But in this release the application launches a new instance of its own after desktop switch and then exits. This makes users feel that the application is always there for them in all desktops. This change has been made after reading one of the comments posted by a reader.
  • 1 Jun 2008 : The feature of launching application is been incorporated. Also few bugs I found have been fixed.
  • 25 July 2008 : Modified the code to encorporate following features:
    • Removed the bug of hooking my own application. Big Grin | :-D
    • Added featue of shortcut-keys to easily navigate between the desktops.
    • Displaying the current desktop name in the application icon tooltip [so you don't get confused on which desktop you are !].
    • Tested on Vista also.

If you find a bug in the application or any feature to be embeded, please let me know, so that I can work on it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
India India
Hello All !
This is Mallinath S. Karkanti, from India. I'm working as a Software Developer in one of the Middle Scale Company... !

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Agent__0079-Dec-14 0:57
professionalAgent__0079-Dec-14 0:57 
Questionhow can we switch desktop in win8 Pin
ytfrdfiw28-Apr-13 14:51
memberytfrdfiw28-Apr-13 14:51 
GeneralMy vote of 5 Pin
ytfrdfiw28-Apr-13 14:50
memberytfrdfiw28-Apr-13 14:50 
QuestionHow can I delete the desktop Pin
jennyyin22-Feb-13 9:44
memberjennyyin22-Feb-13 9:44 
AnswerRe: How can I delete the desktop Pin
Malli_S22-Feb-13 15:48
memberMalli_S22-Feb-13 15:48 
GeneralRe: How can I delete the desktop Pin
jennyyin29-Apr-13 7:36
memberjennyyin29-Apr-13 7:36 
QuestionA desktop with a single application running Pin
kdsasi14-Feb-13 20:56
memberkdsasi14-Feb-13 20:56 
AnswerRe: A desktop with a single application running Pin
Malli_S22-Feb-13 15:51
memberMalli_S22-Feb-13 15:51 
You can try process hooking or Win32 API hook.

This[^] can help you.
[Delegates]      [Virtual Desktop]      [Tray Me !]

-Malli...! Rose | [Rose]

AnswerRe: A desktop with a single application running Pin
chocolatkey3-Jan-15 6:17
memberchocolatkey3-Jan-15 6:17 
QuestionWindows Lock Event Pin
rajutrivium29-Aug-12 21:04
memberrajutrivium29-Aug-12 21:04 
AnswerRe: Windows Lock Event Pin
Malli_S31-Aug-12 4:55
memberMalli_S31-Aug-12 4:55 
GeneralRe: Windows Lock Event Pin
rajutrivium28-Oct-12 19:46
memberrajutrivium28-Oct-12 19:46 
GeneralRe: Windows Lock Event Pin
Malli_S29-Oct-12 20:11
memberMalli_S29-Oct-12 20:11 
GeneralMy vote of 5 Pin
manoj kumar choubey5-Mar-12 21:27
membermanoj kumar choubey5-Mar-12 21:27 
GeneralMy vote of 5 Pin
masaniparesh13-Oct-10 23:49
membermasaniparesh13-Oct-10 23:49 
Generalcrap Pin
mrnt1-Jun-10 23:16
membermrnt1-Jun-10 23:16 
GeneralRe: crap Pin
masaniparesh13-Oct-10 23:49
membermasaniparesh13-Oct-10 23:49 
GeneralRe: crap Pin
Malli_S6-Apr-11 2:13
memberMalli_S6-Apr-11 2:13 
Questioncool, version? Pin
rio_p3-May-09 7:44
memberrio_p3-May-09 7:44 
AnswerRe: cool, version? Pin
Malli_S20-Aug-09 3:54
memberMalli_S20-Aug-09 3:54 
GeneralRe: cool, version? Pin
MatthiWare30-Aug-11 7:12
memberMatthiWare30-Aug-11 7:12 
GeneralRe: cool, version? Pin
Malli_S31-Aug-11 1:26
memberMalli_S31-Aug-11 1:26 
GeneralRe: cool, version? Pin
MatthiWare31-Aug-11 1:33
memberMatthiWare31-Aug-11 1:33 version? Pin
jmiguy18-Jul-12 4:52
memberjmiguy18-Jul-12 4:52 
AnswerRe: version? Pin
Malli_S19-Jul-12 7:19
memberMalli_S19-Jul-12 7:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1509028.1 | Last Updated 25 Jul 2008
Article Copyright 2007 by Malli_S
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid