Happy Noobing, Keep Noobing, be the best noobs!
Categories: VBScript, MFCOM, 326 wordsSend feedback •Tommo asked me is it a quick job to use MFCOM to send message to everyone on one server before scheduled reboot. I quickly checked MFCOM language reference, and found one method:
SendMessage.Findings: when listing sessions, farm-widely, you will get all user sessions, such as ObjFarm.Sessions. But listing sessions by server, as ObjServer.Sessions, it will list the following sessions as well:
Console
ICA-tcp (session id 65536 listening)
RDP-tcp (session id 65537 listening)So in the following script, I have to use to If/elseif to include only session with active state and with non-empty username.
Code:
<package><job id="MFCOM_Send_Message"><comment>File: MFCOM_Send_Message.wsfDescription: Send Message to users who have active sessions on the server.Requirements: WSH 5.5 or higher.Created: 20/5/2008Author: PaulloSendMessage Parameters:ServerNameSessionIDUserNameClientNameTitleMessageMessageStyle 0 = OK Button OnlyTimeout Display time in millisecondsWaitingTime Waiting for response time in milliseconds</comment><runtime><description>Send Message to users.</description><example>CScript //nologo MFCOM_Send_Message.wsf SERVERNAME</example></runtime><reference object="MetaFrameCOM.MetaFrameFarm"/><script language="VBScript">Dim ArgObj, ServerName, ObjServer, ObjSessions, ObjSessionSet ArgObj = WScript.ArgumentsServerName = ArgObj(0)WScript.Echo "Server Name: " & ServerNameSet ObjServer = CreateObject("MetaFrameCOM.MetaFrameServer")ObjServer.Initialize 6, ServerNameFor Each ObjSession in ObjServer.SessionsSessionID = ObjSession.SessionIDUserName = ObjSession.UsernameClientName = ObjSession.ClientNamestrTitle = "System Maintenance Reminder"strMsg = "Please log off in 5 minutes due to regular system maintenance."SessionState = ObjSession.SessionState' WScript.echo "SessionID = " & SessionID & "; UserName = " & UserName & "; ClientName = " & ClientName & "; SessionState = " & SessionState & ";"If UserName = "" Then' When listing sessions for a server, it is listing the listening sessions as well.Elseif SessionState <> 1 Then' Only send message to Active SessionsElseObjSession.SendMessage ServerName,SessionID, UserName, ClientName, strTitle, strMsg, 0, 120000, 120000End IfNext</script></job></package>Permalink