Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Scripts Currently Running

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,41962
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Scripts Currently Running
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Scripts Currently Running - 1/11/2007 5:50:34 PM  1 votes
  dm_4ever


Posts: 2555
Score: 40
Joined: 6/29/2006
From: Orange County, California
Status: offline
Seems there are some admins that have scripts running in the background monitoring or gathering information they need or want.  I've seen some posts where people want to know what scripts are running since you really can't tell by looking in task manager; all you see is wscript.exe or cscript.exe and maybe the PID.  So I was at the end of running a fever and wanted to do something to take my mind off feeling ill and so I put this HTA together.  I apologize if someone has already posted something like this.  Also, forgive me if I didn't comment it well or didn't format it in the manner you are accustomed to (I have my preferred method of structuring my scripts that makes it easy for me to read). 

Save the code below into a HTA file (i.e. "Get Running Scripts.hta") It uses WMI so you need to have Admin rights on the machine you run it on or query.
I've only tested the HTA on an XP & 2003 Server box. ConvertDT Function in the example below only work on XP or higher. Look at the end for a replacement function that should work on Win2k.

NOTE: The commandline property of the Win32_Process class was introduced with WinXP/Win2k3 so you can only see the name of the script running on those boxes.  Also, the commandline property will return NULL if the HTA is launched using the RUNAS command (thanks to kirrilian for discovering this bug).

There are three version of this HTA. You can find two below and one submitted by NssB further down below.

Original Version:

      

Version that accepts alternate credentials (thanks to NssB's contribution):
NOTE: You can NOT provide alternate credentials for the local machine. Queries will be executed using your credentials (impersonate) if no username/password is provided.

Updated 2/4/2007

      

UPDATED: 1/12/2007
Date/Time Conversition Function for Win2k, just replace the ConverDT function in the example above with this one:

      

< Message edited by dm_4ever -- 2/8/2007 9:04:29 AM >


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
 
 
Revisions: 16 | Post #: 1
 
 RE: Scripts Currently Running - 1/11/2007 8:17:11 PM   
  TNO


Posts: 1074
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Holy Running Scripts BatMan


_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to dm_4ever)
 
 
Post #: 2
 
 RE: Scripts Currently Running - 1/12/2007 3:28:30 AM   
  Country73


Posts: 716
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
Pretty slick; I believe I will be able to put this to some good use!

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: Scripts Currently Running - 1/15/2007 8:51:58 AM   
  mrmore

 

Posts: 5
Score: 0
Joined: 11/9/2006
Status: offline
Nice one. Thank you

(in reply to Country73)
 
 
Post #: 4
 
 RE: Scripts Currently Running - 1/16/2007 12:28:57 AM   
  DiGiTAL.SkReAM


Posts: 1170
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Very nice.  Unfortunately, we have about 600+ NT 4.0 servers that we have to support, so I can't use this right now.  *sounds of cursing*


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to mrmore)
 
 
Post #: 5
 
 RE: Scripts Currently Running - 1/19/2007 3:52:38 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
quote:

ORIGINAL: DiGiTAL.SkReAM

Very nice.  Unfortunately, we have about 600+ NT 4.0 servers that we have to support, so I can't use this right now.  *sounds of cursing*



no wonder youre a little "off" somtimes LOL

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 6
 
 RE: Scripts Currently Running - 1/19/2007 8:02:46 AM   
  DiGiTAL.SkReAM


Posts: 1170
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Yeah, well..... I have a bigger smiley avatar than you do!  So there!

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to kirrilian)
 
 
Post #: 7
 
 RE: Scripts Currently Running - 1/19/2007 1:02:41 PM   
  dm_4ever


Posts: 2555
Score: 40
Joined: 6/29/2006
From: Orange County, California
Status: offline
Just wanted to say thank you for the compliments and laughs.  You guys are great

quote:


ORIGINAL: kirrilian
no wonder youre a little "off" somtimes LOL


and

quote:


ORIGINAL: DiGiTAL.SkReAM
Yeah, well..... I have a bigger smiley avatar than you do!  So there!




_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 8
 
 RE: Scripts Currently Running - 1/19/2007 5:06:40 PM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
DOH!!

<--- pwned!!

Just for that, here is a dancing pink elephant and an angry off topic "smiley"



(i know its a cop out...)



< Message edited by kirrilian -- 1/19/2007 5:11:35 PM >


_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to dm_4ever)
 
 
Revisions: 1 | Post #: 9
 
 RE: Scripts Currently Running - 1/19/2007 5:11:14 PM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
btw, dm_4ever, back on topic, when i ran your hta as another user (i do my everyday work as a normal unprivileged user, so i had to run it under my admin acct) i got an error when i tried to run against the local machine. i dont think it was returning the name of the script that was running when i put in a 'on error resume next' statement. i didnt dig in too deeply as to why, i will do that on monday when i get back to work

excellent hta otherwise


_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to kirrilian)
 
 
Post #: 10
 
 RE: Scripts Currently Running - 1/21/2007 4:04:24 AM   
  dm_4ever


Posts: 2555
Score: 40
Joined: 6/29/2006
From: Orange County, California
Status: offline
Definitely let me know what error you're getting so I can take a look. I tried it in a Virtual Machine (WinXP) with an unprivileged user and it seemed to work.  

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to kirrilian)
 
 
Post #: 11
 
 RE: Scripts Currently Running - 1/22/2007 1:59:27 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
i think you misunderstood the user part of it, both of my users are local admins on my workstation, but in order to have admin access on the servers i have to use runas. so i was running your script as my superuser and when it tried to pull the data from the local machine it failed on the script name

this is the process i followed:
use runas to start cmd as my superuser account
start the hta via the terminal
as soon as it opens i get this error:
Line: 48
Error: Invalid use of Null: 'Replace'
I uncommented your on error resume next and it works, but it doesnt print out the script name.

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to dm_4ever)
 
 
Post #: 12
 
 RE: Scripts Currently Running - 1/22/2007 4:42:35 AM   
  DiGiTAL.SkReAM


Posts: 1170
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
As an aside, to view which scripts were running on our NT4.0 boxen, I modified the batch file that calls the script (we use AT to schedule our jobs, and have AT run a cmd file that then runs the script, rather than having it call the .vbs directly.)
ScriptRunner.cmd

      

And then once a night, we have another cmd file that ckicks off that does nothing but delete the extra copies of wscript.exe that we have laying around.
It is kind of a kludge, but... this way we can just pull a list of processes and see what ws_<scriptname>.exe's are running.


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to kirrilian)
 
 
Post #: 13
 
 RE: Scripts Currently Running - 1/22/2007 1:48:57 PM   
  dm_4ever


Posts: 2555
Score: 40
Joined: 6/29/2006
From: Orange County, California
Status: offline
Thank you for that information kirrilian.  I followed your steps and was able to duplicate the error.  It appears that when querying the Win32_Process class after using the runas cmd, the commandline property appears as null.  I'm not too sure how to fix this or get around it at this time, but I'll take a look...perhaps find an alternate method to get the info.

< Message edited by dm_4ever -- 1/22/2007 1:51:58 PM >


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to kirrilian)
 
 
Revisions: 1 | Post #: 14
 
 RE: Scripts Currently Running - 1/27/2007 5:26:16 PM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
quote:

ORIGINAL: dm_4ever

Thank you for that information kirrilian. I followed your steps and was able to duplicate the error. It appears that when querying the Win32_Process class after using the runas cmd, the commandline property appears as null. I'm not too sure how to fix this or get around it at this time, but I'll take a look...perhaps find an alternate method to get the info.


ive thought about it since, it may be related to the fact that runas dumps most of your environment somewhat like cron does in linux, it runs in its own space. i havent tried the runas switches that allow runas to replicate the current environment, but that may be an option.

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to dm_4ever)
 
 
Post #: 15
 
 RE: Scripts Currently Running - 1/30/2007 3:30:43 AM   
  NssB

 

Posts: 30
Score: 0
Joined: 6/25/2006
Status: offline
Hi,


Made a few ammendments to this code. See objWMI function and GetScripts sub. Also a little HTML modded.
Using the SWbem locator/services to connect to a WMI namespace with credentials provided where a remote host is specified.
Normal mgmt: used where host is local. CommandLine method still proving elusive, but perhaps a little easier to manage alternate credentials :)
Oh, and since I like HTA's, I added the MSHTA host controller. My bad
Please do comment.


      

< Message edited by NssB -- 1/30/2007 3:40:28 AM >


_____________________________

Its all about the code!

(in reply to dm_4ever)
 
 
Revisions: 3 | Post #: 16
 
 RE: Scripts Currently Running - 1/30/2007 5:11:55 AM   
  dm_4ever


Posts: 2555
Score: 40
Joined: 6/29/2006
From: Orange County, California
Status: offline
I was actually thinking of changing the method of connection to use SWbemLocator "connectserver" to allow for alternate credentials, so thanks! 

I just noticed the KillScript Sub needs to be updated to reflect the changes.

< Message edited by dm_4ever -- 1/30/2007 5:42:10 AM >


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to NssB)
 
 
Revisions: 1 | Post #: 17
 
 RE: Scripts Currently Running - 1/30/2007 6:06:22 AM   
  dm_4ever


Posts: 2555
Score: 40
Joined: 6/29/2006
From: Orange County, California
Status: offline
I made a few more changes.

- KillScript sub should work
- Added error handeling if credentials supplied are invalid