Click here to Skip to main content
15,112,662 members
Articles / Programming Languages / Visual C++ 9.0
Posted 5 Mar 2009


50 bookmarked

Impersonate Linux's Multi-desktop Feature on Windows Platform

Rate me:
Please Sign up or sign in to vote.
4.87/5 (13 votes)
5 Mar 2009CPOL1 min read
This is a tiny tool to create multi virtual desktop, and allows you to switch between them.



The feature, multi desktops (workspace), is supported by KDE/GNOME on Linux, and it can also be found on Mac OSX.

This tiny tool can impersonate this feature on Windows platform.

Desktop Functions

There is a series of APIs to maintain desktops.

CloseDesktopCloses an open handle to a desktop object.
CreateDesktopCreates a new desktop, associates it with the current window station of the calling process, and assigns it to the calling thread.
CreateDesktopExCreates a new desktop, associates it with the current window station of the calling process, and assigns it to the calling thread.
EnumDesktopsEnumerates all desktops associated with the current window station of the calling process.
EnumDesktopWindowsEnumerates all top-level windows associated with the specified desktop.
GetThreadDesktopRetrieves a handle to the desktop assigned to the specified thread.
GetUserObjectInformationGets information about a window station or desktop object.
GetUserObjectSecurityGets security information for a window station or desktop object.
OpenDesktopOpens the specified desktop object.
OpenInputDesktopOpens the desktop that receives user input.
SetThreadDesktopAssigns the specified desktop to the calling thread.
SetUserObjectInformationSets information about a window station or desktop object.
SetUserObjectSecuritySets security information for a window station or desktop object.
SwitchDesktopMakes a desktop visible and activates it. This enables the desktop to receive input from the user.

How To Create a New Desktop 

The simple code below demonstrates how to create a new desktop.

// create the new desktop
stSecurityAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
stSecurityAttr.bInheritHandle = TRUE;
HDESK hDesktop = ::CreateDesktop( lpszDesktopName
	, 0
	, &stSecurityAttr
if( hDesktop == NULL )
	::MessageBox( m_hWnd, _T("Failed to create new desktop."), 
				_T("Error"), MB_ICONERROR | MB_OK);

// start the Windows Shell(explorer.exe) on the new created desktop
STARTUPINFO stStartInfo = {0};
stStartInfo.cb = sizeof(STARTUPINFO);
stStartInfo.lpDesktop = (LPTSTR)lpszDesktopName;
CString strCmdLine = _T("explorer.exe");
BOOL bRet = ::CreateProcess( NULL
	, strCmdLine.GetBuffer()
	, 0
	, &stStartInfo
	, &stProcInfo
if( !bRet )
	::MessageBox( m_hWnd, _T("Failed to launch the explorer.exe 
			in the new desktop."), _T("Error"), MB_ICONERROR | MB_OK);

// sleep for 3 seconds for the shell ready

// launch another instance on the new created shell
TCHAR tszBuffer[MAX_PATH] = {0};
GetModuleFileName( m_hInstance, tszBuffer, MAX_PATH);
bRet = ::CreateProcess( NULL
	, tszBuffer
	, 0
	, &stStartInfo
	, &stProcInfo


  • 5th March, 2009: Initial post


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


About the Author

Team Leader
China China
Jerry is from China. He was captivated by computer programming since 13 years old when first time played with Q-Basic.

  • Windows / Linux & C++
  • iOS & Obj-C
  • .Net & C#
  • Flex/Flash & ActionScript
  • HTML / CSS / Javascript
  • Gaming Server programming / video, audio processing / image & graphics

Contact: vcer(at)
Chinese Blog:

Comments and Discussions

QuestionIE automatic exit in win7 with uac on, what's wrong? Pin
ocean_sky25-Apr-12 21:39
Memberocean_sky25-Apr-12 21:39 
QuestionDesktop Screenshots ? Pin
User Test22-Dec-09 17:15
MemberUser Test22-Dec-09 17:15 
AnswerRe: Desktop Screenshots ? Pin
User Test22-Dec-09 17:16
MemberUser Test22-Dec-09 17:16 
GeneralGood & simple project Pin
Member 13002109-Apr-09 22:43
MemberMember 13002109-Apr-09 22:43 
GeneralSysinternals Pin
Vahid_N5-Mar-09 11:13
MemberVahid_N5-Mar-09 11:13 
GeneralImpressive Pin
Pablo Robert5-Mar-09 3:59
MemberPablo Robert5-Mar-09 3:59 
GeneralRe: Impressive Pin
Andromeda Shun9-Mar-09 22:20
MemberAndromeda Shun9-Mar-09 22:20 
A solution I like very much for being admin for a certain time is "MachMichAdmin" that can be found here[^].

The page is german, if you don't speek german try a translation service like Babelfish. The software itself is german too, but I've never read the text, so the language doesn't matter (besides in case of errors).

A quick introduction: Download the files (click on "Zur Download-Seite", wait for redirection, then click on "". Extract the zip file to any directory you like. Next, edit the MachMichAdmin.cmd file: Here you must specify the name of your administrator account name and administrator group with "set _Admin_=..." and "set _Group_=...".

If you double-click on the cmd file the command defined with "set _Default_Prog_=..." is executed (that's a cmd window with a differenc background color). You can also drag exe files on the icon, then this application is executed with administrator rights.

Perhaps you can contact the author of the script for a translation (but I don't think he can speak portugese Wink | ;-) ) - He's a journalist from a german computer magazin, so he might help you.

Best regards,
Andromeda Shun
GeneralRe: Impressive Pin
Pablo Robert10-Mar-09 4:10
MemberPablo Robert10-Mar-09 4:10 
GeneralRe: Impressive Pin
Andromeda Shun10-Mar-09 22:35
MemberAndromeda Shun10-Mar-09 22:35 

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

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