yes all the examples are C++ but
you can use the P/Invoke feature in C# to call the native Windows functions.
one example
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace NewDesktop
{
class Program
{
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr CreateDesktop(string lpszDesktop, IntPtr lpszDevice, IntPtr pDevmode, int dwFlags, uint dwDesiredAccess, IntPtr lpsa);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool CloseDesktop(IntPtr hDesktop);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool SwitchDesktop(IntPtr hDesktop);
private const int DESKTOP_CREATEWINDOW = 0x02;
private const int DESKTOP_READOBJECTS = 0x01;
private const int DESKTOP_SWITCHDESKTOP = 0x0100;
private const int DESKTOP_WRITEOBJECTS = 0x0080;
private const int DESKTOP_ALL_ACCESS = DESKTOP_CREATEWINDOW | DESKTOP_READOBJECTS | DESKTOP_SWITCHDESKTOP | DESKTOP_WRITEOBJECTS;
static void Main(string[] args)
{
IntPtr newDesktop = CreateDesktop("NewDesktop", IntPtr.Zero, IntPtr.Zero, 0, (uint)DESKTOP_ALL_ACCESS, IntPtr.Zero);
if (newDesktop == IntPtr.Zero)
{
Console.WriteLine("Failed to create a new desktop.");
return;
}
if (!SwitchDesktop(newDesktop))
{
Console.WriteLine("Failed to switch to the new desktop.");
CloseDesktop(newDesktop);
return;
}
ProcessStartInfo startInfo = new ProcessStartInfo("notepad.exe");
startInfo.UseShellExecute = false;
Process process = new Process { StartInfo = startInfo };
if (!process.Start())
{
Console.WriteLine("Failed to start Notepad.");
}
process.WaitForExit();
SwitchDesktop(newDesktop);
CloseDesktop(newDesktop);
}
}
}