Send Message to active sessions by MFCOM VBScript

Send Message to active sessions by MFCOM VBScript

21/05/08 | by Paullo [mail] | Categories: VBScript, MFCOM

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.wsf
  Description: Send Message to users who have active sessions on the server.
  Requirements: WSH 5.5 or higher.
  Created: 20/5/2008
  Author: Paullo
 
  
  SendMessage Parameters:
 
  ServerName
  SessionID
  UserName
  ClientName
  Title
  Message
  MessageStyle 0 = OK Button Only
  Timeout Display time in milliseconds
  WaitingTime 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, ObjSession
 
Set ArgObj = WScript.Arguments
ServerName = ArgObj(0)
 
WScript.Echo "Server Name: " & ServerName
 
Set ObjServer = CreateObject("MetaFrameCOM.MetaFrameServer")
ObjServer.Initialize 6, ServerName
 
For Each ObjSession in ObjServer.Sessions
    SessionID = ObjSession.SessionID
    UserName = ObjSession.Username
    ClientName = ObjSession.ClientName
    strTitle = "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 Sessions
    Else
        ObjSession.SendMessage ServerName,SessionID, UserName, ClientName, strTitle, strMsg, 0, 120000, 120000
    End If
Next
 
 
</script>
</job>
</package>

Comments, Pingbacks:

No Comments/Pingbacks for this post yet...

This post has 6 feedbacks awaiting moderation...

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))

Ozzy Citrix Noobs

Hi We call us Citrix Noobs, because we are noobs. We are a group of noobs that is heckless and restless. We are not fearing of anything, and we tend to do the best in daily noobing. Join us if you are also noobs, and will keep noobing.

August 2010
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          

Misc

XML Feeds

What is RSS?

powered by b2evolution free blog software