How to get No of users Online and sessions in MSD axapta


How to get No of users Online and sessions


This job gives you the number of current online users.

 static void noofusersOnline(Args _args)  
 {  
 int maxSessions = Info::licensedUsersTotal();  
 userinfo userinfo;  
 int counter;  
 int num;  
 xSession session;  
 if (!maxSessions) //Demo mode  
 maxSessions = 3;  
 num = 0;  
 for(counter = maxSessions;counter;counter--)  
 {  
 session = new xSession(counter, true);  
 if(session && session.userId())  
 {  
 select userinfo where userinfo.id == session.userId();  
 print userinfo.name;  
 }  
 }  
 print "Maximum session id's in Axapta - ", xsession::maxSessionId();  
 pause;  
 }