Title: Virtual Desktop SDK (VtSdk) User Guide and Developer Documentation
Version: 1.0.0
Date: December 9, 2025
Authors: VtSdk Development Team
Revision History:
| Version | Date | Author | Description |
|---|---|---|---|
| 1.0.0 | 2025-12-09 | VtSdk Team | Initial release of user documentation |
This document provides comprehensive guidance for developers and system administrators who need to integrate Windows virtual desktop management capabilities into their .NET applications. It covers installation, configuration, usage, troubleshooting, and maintenance of the Virtual Desktop SDK.
This guide covers:
- Installation and setup of the VtSdk library
- Basic and advanced usage patterns
- API reference and domain models
- Troubleshooting common issues
- Best practices for integration
This guide does not cover:
- Windows operating system administration
- Advanced Windows API programming
- Custom Windows virtual desktop implementations
Primary Audience:
- .NET developers (intermediate to advanced level)
- Application architects designing desktop management features
Secondary Audience:
- System administrators managing Windows environments
- Quality assurance engineers testing virtual desktop functionality
Prerequisites:
- Proficiency in C# and .NET development
- Understanding of asynchronous programming patterns
- Basic knowledge of Windows operating system concepts
- Experience with dependency injection frameworks (recommended)
The Virtual Desktop SDK (VtSdk) is a .NET library that provides programmatic access to Windows virtual desktop management capabilities. It enables applications to:
- Enumerate and monitor virtual desktops
- Switch between desktops programmatically
- Create and remove virtual desktops
- Move application windows between desktops
- Track desktop and window state changes
Desktop Management Applications: Developers building custom desktop managers or virtual desktop enhancers can use VtSdk to create sophisticated user interfaces for desktop organization.
Automation Tools: System administrators can build scripts and tools to automate desktop management tasks, such as organizing applications across multiple desktops based on user preferences or workflows.
Productivity Applications: Applications that enhance user productivity can integrate virtual desktop switching capabilities, such as hotkey managers or workflow automation tools.
Testing Frameworks: QA teams can use the SDK to create automated tests that verify application behavior across different virtual desktop configurations.
Supported Platforms:
- Windows 10 version 1607 or later
- Windows 11 (all versions)
- .NET 8.0 or later
Execution Context:
- Must run in user session (not as a system service)
- Requires access to Windows desktop APIs
- COM components must be available and registered
Resource Requirements:
- Minimal memory footprint (< 10MB)
- No significant CPU usage during normal operation
- Network access not required for core functionality
Hardware Requirements:
- x64 processor architecture
- 100 MB available disk space
- 512 MB RAM (additional for applications using the SDK)
Software Requirements:
- Windows 10 version 1607 (Build 14393) or later
- .NET 8.0 Runtime or .NET 8.0 SDK (for development)
- Windows Virtual Desktop feature enabled
Preconditions:
- .NET 8.0 SDK installed
- Access to NuGet package repository
- Project targets .NET 8.0 or later
Steps:
- Open your .NET project in Visual Studio or your preferred IDE.
- Open the Package Manager Console (Tools → NuGet Package Manager → Package Manager Console).
- Execute the following command:
Install-Package VtSdk - Alternatively, use the .NET CLI:
dotnet add package VtSdk
Post-conditions:
- VtSdk package is added to your project dependencies
- All required assemblies are available in your project
Preconditions:
- Git client installed
- .NET 8.0 SDK installed
- Access to the VtSdk repository
Steps:
-
Clone the repository:
git clone <repository-url> cd vtSdk -
Build all projects:
dotnet build VtSdk.sln -
(Optional) Run the demonstration application:
dotnet run --project VtSdk.Demo
Post-conditions:
- All projects compile successfully
- Demo application runs and demonstrates basic functionality
No additional configuration is required for basic usage. The SDK automatically detects and adapts to the Windows environment.
For ASP.NET Core applications:
// In Program.cs or Startup.cs
using VtSdk.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Add VtSdk services
builder.Services.AddVirtualDesktopSdk();
// Configure options if needed
builder.Services.Configure<VirtualDesktopOptions>(options =>
{
options.DefaultDesktopName = "Main Desktop";
options.EnableEventMonitoring = true;
});
var app = builder.Build();For other DI containers:
using VtSdk;
// Register services manually
var services = new ServiceCollection();
services.AddSingleton<IVirtualDesktopManager, WindowsVirtualDesktopManager>();
services.AddSingleton<VirtualDesktopService>();
var provider = services.BuildServiceProvider();Procedure: Verify Installation
- Create a new console application.
- Add the VtSdk package reference.
- Add the following test code:
using VtSdk;
try
{
using var manager = new VirtualDesktopManager();
var desktops = manager.GetDesktops();
Console.WriteLine($"Found {desktops.Count} virtual desktops");
Console.WriteLine("Installation successful!");
}
catch (Exception ex)
{
Console.WriteLine($"Installation failed: {ex.Message}");
}- Run the application.
- Verify that the application detects virtual desktops without errors.
Purpose: Retrieve information about all available virtual desktops.
Preconditions:
- Windows virtual desktops are enabled
- Application has access to desktop APIs
- VtSdk is properly initialized
Steps:
-
Create a
VirtualDesktopManagerinstance:using var manager = new VirtualDesktopManager();
-
Call the
GetDesktops()method:var desktops = manager.GetDesktops();
-
Iterate through the results:
foreach (var desktop in desktops) { Console.WriteLine($"Desktop: {desktop.Name}"); Console.WriteLine($"Index: {desktop.Index}"); Console.WriteLine($"Windows: {desktop.WindowCount}"); Console.WriteLine($"Active: {desktop.IsActive}"); }
Expected Results:
- List of all virtual desktops with their properties
- Current desktop marked as active
Error Conditions:
VirtualDesktopExceptionif Windows APIs are unavailable- Empty collection if virtual desktops are disabled
Purpose: Programmatically switch to a different virtual desktop.
Preconditions:
- Target desktop exists and is accessible
- Application has permission to switch desktops
- VtSdk manager is initialized
Steps:
-
Obtain the target desktop identifier:
var desktops = manager.GetDesktops(); var targetDesktop = desktops.FirstOrDefault(d => d.Name.Contains("Work")); if (targetDesktop == null) return;
-
Switch to the target desktop:
bool success = await manager.SwitchToDesktopAsync(targetDesktop.Id);
-
Verify the switch (optional):
var current = manager.GetCurrentDesktop(); Console.WriteLine($"Current desktop: {current?.Name}");
Expected Results:
- Desktop switch completes successfully
- User interface updates to show the new desktop
- Return value is
true
Error Conditions:
ArgumentExceptionif desktop ID is invalidVirtualDesktopExceptionif switch operation failsfalsereturn value indicates operation failed
Purpose: Create a new virtual desktop with optional custom name.
Preconditions:
- Windows virtual desktops are enabled
- User has permission to create desktops
- System has capacity for additional desktops
Steps:
-
Prepare desktop creation parameters:
string desktopName = "Development Workspace";
-
Create the new desktop:
var newDesktop = await manager.CreateDesktopAsync(desktopName);
-
(Optional) Switch to the new desktop:
await manager.SwitchToDesktopAsync(newDesktop.Id);
-
Verify creation:
Console.WriteLine($"Created desktop: {newDesktop.Name} (ID: {newDesktop.Id})");
Expected Results:
- New desktop is created and available
- Desktop appears in system taskbar
VirtualDesktopobject returned with valid properties
Error Conditions:
VirtualDesktopExceptionif creation fails- System limit reached (typically 20 desktops)
Purpose: Move an application window from one virtual desktop to another.
Preconditions:
- Source window exists and is accessible
- Target desktop exists
- Application has permission to manipulate windows
Steps:
-
Identify the window to move:
// Get all windows var allWindows = manager.GetAllWindows(); // Find specific window by title var targetWindow = allWindows.FirstOrDefault(w => w.Title.Contains("Visual Studio")); if (targetWindow == null) return;
-
Select target desktop:
var desktops = manager.GetDesktops(); var targetDesktop = desktops.FirstOrDefault(d => d.Name.Contains("Dev")); if (targetDesktop == null) return;
-
Move the window:
bool success = await manager.MoveWindowToDesktopAsync( targetWindow.Handle, targetDesktop.Id);
Expected Results:
- Window moves to target desktop
- Window disappears from current desktop
- Return value is
true
Error Conditions:
ArgumentExceptionif window handle or desktop ID is invalidVirtualDesktopExceptionif move operation failsfalsereturn value indicates operation failed
Purpose: Track changes to virtual desktop state and windows.
Preconditions:
- Event monitoring enabled in configuration
- Application can handle asynchronous events
Steps:
-
Set up event handlers:
manager.DesktopCreated += (sender, args) => { Console.WriteLine($"Desktop created: {args.Desktop.Name}"); }; manager.DesktopDestroyed += (sender, args) => { Console.WriteLine($"Desktop destroyed: {args.DesktopId}"); }; manager.DesktopChanged += (sender, args) => { Console.WriteLine($"Switched to desktop: {args.NewDesktop.Name}"); };
-
Enable monitoring:
manager.EnableEventMonitoring();
-
Keep application running to receive events:
await Task.Delay(Timeout.Infinite);
Expected Results:
- Events fired when desktops are created, destroyed, or switched
- Event arguments contain relevant desktop information
Symptoms:
- Exception thrown when creating
VirtualDesktopManager - Message indicates Windows API unavailable
Possible Causes:
- Windows virtual desktops not enabled
- Running as system service instead of user session
- COM components not registered
Resolution Steps:
- Verify Windows version supports virtual desktops (Windows 10 1607+).
- Ensure virtual desktops are enabled in system settings.
- Confirm application runs in user session, not as service.
- Try running as administrator if permission issues suspected.
Symptoms:
- Methods return
falsewithout throwing exceptions - Desktop state doesn't change as expected
Possible Causes:
- Windows is in a restricted state
- Another application is managing desktops
- System policy restrictions
Resolution Steps:
- Check Windows Event Viewer for related errors.
- Verify no other desktop management software is running.
- Test with minimal code to isolate the issue.
- Restart Windows Explorer if desktop shell issues suspected.
Symptoms:
MoveWindowToDesktopAsyncreturnsfalse- Window remains on current desktop
Possible Causes:
- Window belongs to system process
- Window has special protection (UAC dialogs, etc.)
- Target desktop no longer exists
Resolution Steps:
- Verify window handle is valid and window still exists.
- Check if window belongs to current user session.
- Ensure target desktop still exists.
- Try moving different windows to test if issue is window-specific.
| Error Message | Meaning | Resolution |
|---|---|---|
VirtualDesktopNotSupportedException |
Windows version doesn't support virtual desktops | Upgrade to Windows 10 1607+ or Windows 11 |
ComInitializationException |
COM components failed to initialize | Restart application or system |
AccessDeniedException |
Insufficient permissions | Run as administrator or check user rights |
InvalidDesktopIdException |
Desktop identifier is invalid | Refresh desktop list and retry |
WindowNotFoundException |
Window handle is invalid | Refresh window list and retry |
Community Support:
- GitHub Issues: Report bugs and request features
- Stack Overflow: Ask questions with
vtsdktag
Professional Support:
- Contact the development team for enterprise support options
- Check documentation repository for known issues and workarounds
Uninstallation may be necessary when:
- Removing the SDK from development environment
- Upgrading to incompatible version
- Troubleshooting integration issues
- Cleaning up unused dependencies
Preconditions:
- Project is open in development environment
- No code dependencies on VtSdk remain
Steps:
- Open Package Manager Console in Visual Studio.
- Execute uninstall command:
Uninstall-Package VtSdk - Alternatively, use .NET CLI:
dotnet remove package VtSdk - Clean and rebuild project:
dotnet clean dotnet build
Post-conditions:
- VtSdk package removed from project
- No references to VtSdk assemblies
Preconditions:
- Source code repository cloned locally
- No other projects depend on local VtSdk build
Steps:
- Remove cloned repository:
rd /s vtSdk - Clean NuGet cache (optional):
dotnet nuget locals all --clear - Remove any local package references.
Post-conditions:
- All VtSdk source code and build artifacts removed
- System ready for clean reinstallation if needed
The VtSdk library does not create persistent system data. However, applications using VtSdk may have stored configuration data that should be cleaned up:
- Remove application configuration files containing VtSdk settings.
- Clear any cached desktop state information.
- Reset application preferences to defaults.
Procedure: Verify Uninstallation
- Attempt to build project that previously used VtSdk.
- Verify compilation errors indicate missing VtSdk references.
- Confirm no VtSdk assemblies in output directory.
Main entry point for simple usage scenarios.
public class VirtualDesktopManager : IDisposable
{
// Desktop enumeration
IReadOnlyCollection<VirtualDesktop> GetDesktops()
VirtualDesktop? GetCurrentDesktop()
// Desktop switching
Task<bool> SwitchToDesktopAsync(DesktopId desktopId)
Task<bool> SwitchToNextDesktopAsync()
Task<bool> SwitchToPreviousDesktopAsync()
// Desktop management
Task<VirtualDesktop> CreateDesktopAsync(string? name = null)
Task<bool> RemoveDesktopAsync(DesktopId desktopId)
// Window management
Task<bool> MoveWindowToDesktopAsync(WindowHandle windowHandle, DesktopId desktopId)
IReadOnlyCollection<Window> GetWindowsForDesktop(DesktopId desktopId)
IReadOnlyCollection<Window> GetAllWindows()
// Event monitoring
void EnableEventMonitoring()
event EventHandler<DesktopEventArgs> DesktopCreated
event EventHandler<DesktopEventArgs> DesktopDestroyed
event EventHandler<DesktopChangedEventArgs> DesktopChanged
}Application service for complex scenarios with dependency injection.
public class VirtualDesktopService
{
// All VirtualDesktopManager methods plus orchestration
Task<bool> MoveCurrentWindowToDesktopAsync(DesktopId desktopId)
// Additional business logic methods
Task<VirtualDesktop> GetOrCreateDesktopAsync(string name)
Task<bool> OrganizeWindowsByApplicationAsync()
}public readonly record struct DesktopId(Guid Value);
public readonly record struct WindowHandle(IntPtr Value);public class VirtualDesktop
{
DesktopId Id { get; }
string Name { get; }
int Index { get; }
bool IsActive { get; }
IReadOnlyCollection<Window> Windows { get; }
int WindowCount { get; }
}
public class Window
{
WindowHandle Handle { get; }
string Title { get; }
int ProcessId { get; }
bool IsVisible { get; }
bool IsMainWindow { get; }
}COM (Component Object Model): Microsoft's framework for developing software components that can interact with each other.
Dependency Injection: A design pattern where dependencies are provided to a class rather than the class creating them itself.
Domain-Driven Design (DDD): An approach to software development that centers the development on programming a domain model.
NuGet: The package manager for .NET that makes it easy to install and update libraries and tools.
Virtual Desktop: A feature in Windows that allows users to organize windows and applications across multiple desktop spaces.
Window Handle: A unique identifier assigned to each window by the Windows operating system.
API Reference: See Appendix A
Configuration: See Installation and Configuration section
Creating desktops: See Procedure: Create New Desktop
Dependency injection: See Installation and Configuration section
Desktop enumeration: See Procedure: Enumerate Virtual Desktops
Desktop switching: See Procedure: Switch Between Desktops
Error handling: See Troubleshooting and Error Handling section
Event monitoring: See Procedure: Monitor Desktop Changes
Installation: See Installation and Configuration section
Moving windows: See Procedure: Move Window to Different Desktop
Troubleshooting: See Troubleshooting and Error Handling section
Uninstallation: See Information for Uninstallation section