Select blog: [OZCTX]
Select skin: [basic] [custom] [l33t_gray] [miami_blue] [natural_pink] [nifty_corners] [originalb2] [skinners_guide] [wpc_default]

Ozzy Citrix Noobs

Happy Noobing, Keep Noobing, be the best 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.

Category: MFCOM

21/05/08

11:51:50 am Permalink Send Message to active sessions by MFCOM VBScript   English (AU)

Categories: VBScript, MFCOM, 326 words

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>
Send feedbackPermalinkPermalink

:: Archives

[Login...]


powered by b2evolution free blog software