473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

MOM script for Citrix idle sessions: ? about running shell commands

At the end of this message I've pasted a script we're trying to modify
slightly. I don't believe it is VBscript or javascript but these are
the closest groups I could find with my limited programming knowledge.
Basically, we are trying to add a few lines to this script that will
execute a few shell commands (see comments at the very end of the
code). We think this may be ActionScript2 but aren't sure.

If you can offer any help, or know of a more approrpriate place for me
to post this message, please let me know. Thanks!

===========================

/ event constants
var EVENT_TYPE_SUCCESS = 0;
var EVENT_TYPE_ERROR = 1;
var EVENT_TYPE_WARNING = 2;
var EVENT_TYPE_INFORMATION = 4;

// WMI constants
var WBEM_IMPERSONATE = 3;

// Citrix WMI constants
var SESSION_ACTIVE = 0;
function GenerateEvent(EventNo, EventType, Message) {
var MyEvent = ScriptContext.CreateEvent();
MyEvent.Message = Message;
MyEvent.EventNumber = EventNo;
MyEvent.EventType = EventType;
MyEvent.EventSource = "Citrix MetaFrame";

ScriptContext.Submit(MyEvent);
}

function logError(message, error)
{
var str = SCRIPT_NAME + ":\n" + message;

if (error)
{
var num = (error.number<0) ? error.number+0x100000000 :
error.number;
var estr = error.description;

if (num == 0x80010105)
estr += " [RPC_E_SERVERFAULT: The server threw an
exception.]";
else if (num == 0x80041001)
estr += " [WBEM_E_FAILED]";
else if (num == 0x80010108)
estr += " [RPC_E_DISCONNECTED]";
else if (num == 0x8007007e)
estr += " [ERROR_MOD_NOT_FOUND: The specified module could
not be found.]";
else if (num == 0x80041010)
estr += " [WBEM_E_INVALID_CLASS]";
else if (num == 0x8004100e)
estr += " [WBEM_E_INVALID_NAMESPACE]";

if (estr == "")
estr = "<error description not given>";
str += ":\n\tReceived error: 0x" + num.toString(16) + ": " +
estr;
}

GenerateEvent(2, EVENT_TYPE_ERROR, str); }

function ConvertWMITime(wmitime)
{
var year = wmitime.substring(0, 4);
var month = wmitime.substring(4, 6) - 1;
var day = wmitime.substring(6, 8);
var hour = wmitime.substring(8, 10);
var minute = wmitime.substring(10, 12);
var second = wmitime.substring(12, 14);

var date = new Date(year, month, day, hour, minute, second);
return date;
}

function Main()
{
// script should only be run in response to a timed event
if (!ScriptContext.IsEvent()) {
GenerateEvent(1, EVENT_TYPE_ERROR, SCRIPT_NAME +
": this script can only be run in response to an event");
return;
}

// parse parameters: 'limit' is the number of minutes the session
// must have been idle before an event is generated
var limit;
try {
limit = ScriptContext.Parameters.Get("limit");
} catch (e) {
logError("Can't retrieve script parameter", e);
return;
}

// coerce into an integer
var nrminutes = parseInt(limit);
if (isNaN(nrminutes) || nrminutes <= 0) {
logError("`limit' parameter (" + limit +
") is not a valid positive number");
return;
}

// first, retrieve all instances of MetaFrame_Session
var locator, service, sessionobj;
try {
locator = new ActiveXObject("WbemScripting.SWbemLocator");
service = locator.ConnectServer("", "root/Citrix");
sessionobj = service.Get("MetaFrame_Session");
sessionobj.Security_.impersonationLevel = WBEM_IMPERSONATE;
} catch (e) {
logError("WMI error retrieving session object", e);
return;
}

var instances;
try {
instances = sessionobj.Instances_();
} catch (e) {
logError("WMI error retrieving session instances", e);
return;
}
// next check the idle time of active sessions and raise an event
// if it exceeds the limit given in the parameter
try {
// gratuitous access to Count to generate error if instances
// can't be retrieved
var nrsessions = instances.Count;

var e = new Enumerator(instances);
for (; !e.atEnd(); e.moveNext()) {
var session = e.item();
if (session.SessionState != SESSION_ACTIVE)
continue;

var last = ConvertWMITime(session.LastInputTime);
var now = ConvertWMITime(session.CurrentTime);

var diff = (now.getTime() - last.getTime()) / (1000 * 60);

if (diff > nrminutes) {

var user = "(unknown user)";
try {
var userobj = service.Get(session.SessionUser);
userobj.Security_.impersonationLevel =
WBEM_IMPERSONATE;
user = userobj.UserName;
} catch (e) {
}

var ev = ScriptContext.CreateEvent();
ev.EventNumber = EVENT_ID;
ev.EventType = EVENT_TYPE_ERROR;
ev.EventSource = "Citrix MetaFrame";
ev.Message = "Session " + session.SessionID + " for
user " +
user + " has been idle for too long.";
ev.UserName = user;
ev.SetEventParameter(session.SessionID);
ev.SetEventParameter(Math.round(diff));
ev.SetEventParameter(nrminutes);
ScriptContext.Submit(ev);

// XXXXXXXXXXXXXXX CHANGE TO INSERT HERE XXXXXXXXXXXXXXXXXXXXXX
// We need to change this script so that instead of running the
// commands above (that write an entry to the Event Log), it instead
// executes some external shell commands. It would look something
like
// this in VB script:
//
// oShell.Run("c:\utils\pskill winword.exe %username%")
// oShell.Run("c:\utils\pskill excel.exe %username%")
//
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXX
}
Jul 17 '05 #1
0 5979

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Ashot | last post by:
This is sort of both Python and Vim related (which is why I've posted to both newsgroups). Python related: ---------------------- I have been frustrated for quite some time with a lack of a...
4
by: Bill Davy | last post by:
To make life easier for my users, I'd like to colour my prompt string (as handed to raw_input()) a different colour to that produced by print. I'm using Python 2.4.1 and IDLE 1.1.1 on Windows XP. ...
11
by: KathyB | last post by:
Hi, I have an asp.net app running on an Intranet. From one of my aspx pages I would like to run a javascript that will run the following command OUTSIDE of the IIS/asp.net environment on the...
8
by: Harlin Seritt | last post by:
I have a remote linux server where I can only access it via ssh. I have a script that I need to have run all the time. I run like so: python script.py & It runs fine. When I log off ssh I...
1
by: dumbandjaded | last post by:
Hey everyone, just a quick general question about using the main python shell (I'm using IDLE on Windows to be exact). Whenever I print some really long output to the screen (> 3000 characters...
5
by: Art | last post by:
Hi, We have some applications that run on a Citrix server. I would like to run one of them, a reporting app, from within a VB.net application. If I log into the Citrix server with remote...
6
by: MrBlueSky | last post by:
Hi, I'm trying to use IDLE to develop My First Python App and my head hurts... I've a file called spalvi.py with this in it: from Test import * firstTest("Mike") And a file called Test.py...
3
by: Mark | last post by:
Hello, What I need to know is if there is a better method to run/edit modules on my pc. I'm currently running the IDLE shell under Python 2.5, on Windows XP. Every time I edit my .txt or .py...
5
by: inetquestion | last post by:
I am looking for a web interface for shell commands or shell scripts. Does anyone know of any exexisting php scripts which would solve this requirement? PHP form accepts input from a user, then...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.