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