// this can fail sometimes, that's why we set numberOfUserDesktops to 1
try
{
numberOfUserDesktops=newManagementObjectSearcher(scope,newSelectQuery("select * from win32_Perfrawdata_TermService_TerminalServicesSession")).Get().Count-1;// don't count Service desktop
}
catch
{
}
varnumberOfUserDesktops=newManagementObjectSearcher(scope,newSelectQuery("select * from win32_Perfrawdata_TermService_TerminalServicesSession")).Get().Count-1;// don't count Service desktop