Testing with VirtualBox¶
This guide walks you through setting up a Windows virtual machine for testing Simple RDP.
Prerequisites¶
- VirtualBox installed
- Windows ISO image (download from Microsoft)
- At least 4GB RAM and 50GB disk space available
Setting Up the VM¶
1. Create a New Virtual Machine¶
- Open VirtualBox and click New
- Configure the VM:
- Name:
Windows-RDP-Test - Type: Microsoft Windows
- Version: Windows 11 (64-bit)
- Name:
- Allocate resources:
- Memory: 4096 MB (minimum)
- Processors: 2 cores
- Hard disk: 50 GB (dynamically allocated)
2. Configure Network¶
Network Configuration
The VM must be accessible from your host machine.
Gives the VM its own IP on your local network:
- Select the VM → Settings → Network
- Set Attached to:
Bridged Adapter - Select your active network interface
Creates a private network between host and VM:
- Go to File → Host Network Manager
- Click Create to add a host-only network
- In VM settings → Network → Adapter 2
- Enable and set to
Host-only Adapter
3. Install Windows¶
- Start the VM and select your Windows ISO
- Follow the installation wizard
- Create a local account (skip Microsoft account)
Windows Activation
For testing purposes, you can use Microsoft Activation Scripts:
- Open PowerShell as Administrator
- Run:
- Select option
1for HWID activation
Enabling Remote Desktop¶
1. Enable RDP in Windows Settings¶
- Open Settings → System → Remote Desktop
- Toggle Remote Desktop to On
- Click Confirm when prompted
Alternative: Using System Properties
- Press ++win+r++, type
sysdm.cpl, press ++enter++ - Go to Remote tab
- Select Allow remote connections to this computer
- Uncheck Allow connections only from computers running Remote Desktop with Network Level Authentication (optional, for compatibility)
- Click OK
2. Configure Firewall¶
Remote Desktop should automatically configure the firewall. To verify:
- Open Windows Defender Firewall
- Click Allow an app through firewall
- Ensure Remote Desktop is checked for your network type
3. Note Your Credentials¶
You'll need:
- Username: Your Windows account name
- Password: Your Windows account password
Password Required
RDP requires a password. If your account has no password, set one:
- Press ++ctrl+alt+del++
- Click Change a password
- Set a password
Getting the VM's IP Address¶
From Windows (inside VM)¶
Open Command Prompt or PowerShell and run:
Look for the IPv4 Address under your network adapter:
Ethernet adapter Ethernet:
IPv4 Address. . . . . . . . . . . : 192.168.1.105
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
From Host (using VirtualBox)¶
Testing the Connection¶
1. Verify RDP Port is Open¶
From your host machine:
2. Test with Simple RDP¶
Create a test script:
import asyncio
from simple_rdp import RDPClient
async def test_connection():
async with RDPClient(
host="192.168.1.105", # Your VM's IP
username="YourUsername",
password="YourPassword",
) as client:
print(f"Connected: {client.width}x{client.height}")
# Wait for desktop to render
await asyncio.sleep(3)
# Take a screenshot
img = await client.screenshot()
img.save("vm_screenshot.png")
print("Screenshot saved to vm_screenshot.png")
# Test mouse click
await client.mouse_click(client.width // 2, client.height // 2)
print("Clicked center of screen")
# Test keyboard
await client.send_key(0xE05B) # Windows key
await asyncio.sleep(0.5)
await client.send_key(0x01) # Escape
print("Tested keyboard input")
asyncio.run(test_connection())
Run it:
3. Using Environment Variables¶
For convenience, create a .env file:
Then use:
import asyncio
import os
from dotenv import load_dotenv
from simple_rdp import RDPClient
load_dotenv()
async def main():
async with RDPClient(
host=os.environ["RDP_HOST"],
username=os.environ["RDP_USER"],
password=os.environ["RDP_PASS"],
) as client:
await asyncio.sleep(2)
await client.save_screenshot("test.png")
asyncio.run(main())
Troubleshooting¶
Connection refused
- Verify RDP is enabled in Windows
- Check Windows Firewall allows RDP
- Ensure the VM is running and accessible
- Verify the IP address is correct
Authentication failed
- Check username and password are correct
- Ensure the Windows account has a password set
- Try using
COMPUTERNAME\usernameformat
Network unreachable
- Check VirtualBox network adapter settings
- Verify host and VM are on the same network (for bridged)
- Try pinging the VM from host:
ping 192.168.1.105
Timeout
- The VM may be sleeping - wake it first
- Check if another RDP session is active
- Increase connection timeout if needed
VM Management Tips¶
Snapshots¶
Take snapshots before testing to easily restore:
# Create snapshot
VBoxManage snapshot "Windows-RDP-Test" take "clean-state"
# Restore snapshot
VBoxManage snapshot "Windows-RDP-Test" restore "clean-state"
Headless Mode¶
Run the VM without a GUI window: