Enabling Remote Desktop remotely

Ran into a situation where I needed to get remote desktop access to a machine where I hadn't previously enabled it.  I'm not the first to post about this, but the other posts I've seen didn't have information on opening the firewall (XP SP2).  Here's one solution:

 reg add "//machinename/HKLM/SYSTEM/CurrentControlSet/Control/Terminal Server" /f /v fDenyTSConnections /t REG_DWORD /d 0

reg add "//machinename/HKLM/SYSTEM/CurrentControlSet/Services/SharedAccess/Parameters/FirewallPolicy/DomainProfile/GloballyOpenPorts/List" /f /v 3389:TCP /t REG_SZ /d 3389:TCP:*:Enabled:@xpsp2res.dll,-22009

reg add "//machinename/HKLM/SYSTEM/CurrentControlSet/Services/SharedAccess/Parameters/FirewallPolicy/StandardProfile/GloballyOpenPorts/List" /f /v 3389:TCP /t REG_SZ /d 3389:TCP:*:Enabled:@xpsp2res.dll,-22009

You have to be an administrator, of course. You can reboot the machine by typing

 shutdown -m \\machinename -r -f