473,655 Members | 3,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_SUCC ESS = 0;
var EVENT_TYPE_ERRO R = 1;
var EVENT_TYPE_WARN ING = 2;
var EVENT_TYPE_INFO RMATION = 4;

// WMI constants
var WBEM_IMPERSONAT E = 3;

// Citrix WMI constants
var SESSION_ACTIVE = 0;
function GenerateEvent(E ventNo, EventType, Message) {
var MyEvent = ScriptContext.C reateEvent();
MyEvent.Message = Message;
MyEvent.EventNu mber = EventNo;
MyEvent.EventTy pe = EventType;
MyEvent.EventSo urce = "Citrix MetaFrame";

ScriptContext.S ubmit(MyEvent);
}

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

if (error)
{
var num = (error.number<0 ) ? error.number+0x 100000000 :
error.number;
var estr = error.descripti on;

if (num == 0x80010105)
estr += " [RPC_E_SERVERFAU LT: The server threw an
exception.]";
else if (num == 0x80041001)
estr += " [WBEM_E_FAILED]";
else if (num == 0x80010108)
estr += " [RPC_E_DISCONNEC TED]";
else if (num == 0x8007007e)
estr += " [ERROR_MOD_NOT_F OUND: 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\tRecei ved error: 0x" + num.toString(16 ) + ": " +
estr;
}

GenerateEvent(2 , EVENT_TYPE_ERRO R, str); }

function ConvertWMITime( wmitime)
{
var year = wmitime.substri ng(0, 4);
var month = wmitime.substri ng(4, 6) - 1;
var day = wmitime.substri ng(6, 8);
var hour = wmitime.substri ng(8, 10);
var minute = wmitime.substri ng(10, 12);
var second = wmitime.substri ng(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_ERRO R, 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.P arameters.Get(" limit");
} catch (e) {
logError("Can't retrieve script parameter", e);
return;
}

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

// first, retrieve all instances of MetaFrame_Sessi on
var locator, service, sessionobj;
try {
locator = new ActiveXObject(" WbemScripting.S WbemLocator");
service = locator.Connect Server("", "root/Citrix");
sessionobj = service.Get("Me taFrame_Session ");
sessionobj.Secu rity_.impersona tionLevel = WBEM_IMPERSONAT E;
} catch (e) {
logError("WMI error retrieving session object", e);
return;
}

var instances;
try {
instances = sessionobj.Inst ances_();
} 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(inst ances);
for (; !e.atEnd(); e.moveNext()) {
var session = e.item();
if (session.Sessio nState != SESSION_ACTIVE)
continue;

var last = ConvertWMITime( session.LastInp utTime);
var now = ConvertWMITime( session.Current Time);

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

if (diff > nrminutes) {

var user = "(unknown user)";
try {
var userobj = service.Get(ses sion.SessionUse r);
userobj.Securit y_.impersonatio nLevel =
WBEM_IMPERSONAT E;
user = userobj.UserNam e;
} catch (e) {
}

var ev = ScriptContext.C reateEvent();
ev.EventNumber = EVENT_ID;
ev.EventType = EVENT_TYPE_ERRO R;
ev.EventSource = "Citrix MetaFrame";
ev.Message = "Session " + session.Session ID + " for
user " +
user + " has been idle for too long.";
ev.UserName = user;
ev.SetEventPara meter(session.S essionID);
ev.SetEventPara meter(Math.roun d(diff));
ev.SetEventPara meter(nrminutes );
ScriptContext.S ubmit(ev);

// XXXXXXXXXXXXXXX CHANGE TO INSERT HERE XXXXXXXXXXXXXXX XXXXXXX
// 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%")
//
// XXXXXXXXXXXXXXX XXXXXXXXXXXXXXX XXXXXXXXXXXXXXX XXXXXXXXXXXXXXX
}
Jul 17 '05 #1
0 6010

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

Similar topics

15
7377
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 history command in IDLE (in fact with IDLE in general). Often I'll develop new code at the command line, testing each line as I go. Currently I have to copy and paste, removing outputs and the ">>>" at each line. Is it perhaps possible to make...
4
8220
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. Is it possible, and if so, how? tia, Bill
11
78099
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 CLIENT machine (remember, a controlled Intranet!). Is this possible? This windows program needs to be opened and data entered periodically while using the asp.net app as well. The exe runs in a dos command window, tied to a Citrix ica file.
8
38118
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 notice that the script died when I logged off. How do I make sure it stays running? thanks,
1
2716
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 or so), my shell will start lagging very badly. I'm not sure if the shell keeps some memory dedicated to this already outputted data or what, but either way I can't seme to unlock these resources. Restarting just the shell doesn't help, so I end...
5
11281
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 desktop, I can type a command line that will do what I want. My VB.net application is not on that Citrix server. I'm afraid that if I map a drive to the Citrix box and shell out to the reporting app that I'll take it over -- that is, my use of the...
6
1787
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 with this in it: def firstTest(name): print "Yo",name
3
1931
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 file, I have to restart the IDLE shell for the changes to take effect. It's pretty annoying. Assuming IDLE is already open, here are the steps that I typically take:
5
5078
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 passes these as arguments to a configurable shell script or OS command. I would like for the output generated from the shell script/command shall be displayed in a new javascript window once the form is submitted. Optimally a user should not...
0
8380
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8710
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8598
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1598
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.