Author Topic: Script to detect running process  (Read 3132 times)

paljets

  • Newbie
  • *
  • Posts: 1
Script to detect running process
« on: February 05, 2015, 11:25:51 am »
So I need to write a script that does the following:

Check every 60 seconds to see if a process under the user's user-id is running.  If it is NOT running, issue a ts disconnect

the script needs to check every 60 seconds till the process is no longer found, then issue the disconnect..

Anyone help?

DAG_P6

  • Full Member
  • ***
  • Posts: 184
  • WinBatch rocks, and so does Wilson WindowWare!
    • WizardWrx
Re: Script to detect running process
« Reply #1 on: February 13, 2015, 01:06:27 am »
The Process Extender probably has everything you need to do so.
David A. Gray
You are more important than any technology.

td

  • Tech Support
  • *****
  • Posts: 2141
    • WinBatch
Re: Script to detect running process
« Reply #2 on: February 13, 2015, 06:44:12 am »
Here is a link to an example that uses the Process Extender and WMI to obtain the user name associated with a process.

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WIL~Extenders/Process~ID+Get~Username~from~a~Process.txt

The Terminal Service extender's wtsDisonnectSession function can be used to disconnect a session.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


ChuckC

  • Full Member
  • ***
  • Posts: 117
Re: Script to detect running process
« Reply #3 on: February 20, 2015, 08:24:33 am »
Also of interest... Take a look at the sample script for the Terminal Services extender, as it shows how to use the extender to enumerate all of the processes running within a specified [e.g. the current] TS session.   For purposes of simply determining if a process is running, it will pull double duty and nix out the need for using the Process Extender.  Since it is the session within which the process runs, and not the actual username under which the process runs, which is important, the TS extender can provide all the required information w/o having to resort to using a combination of the Process extender and WMI.


Here is a link to an example that uses the Process Extender and WMI to obtain the user name associated with a process.

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WIL~Extenders/Process~ID+Get~Username~from~a~Process.txt

The Terminal Service extender's wtsDisonnectSession function can be used to disconnect a session.

td

  • Tech Support
  • *****
  • Posts: 2141
    • WinBatch
Re: Script to detect running process
« Reply #4 on: February 20, 2015, 01:18:01 pm »
It would appear that whether or not the user id is important is contingent on several factors that OP did not specify.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


ChuckC

  • Full Member
  • ***
  • Posts: 117
Re: Script to detect running process
« Reply #5 on: February 23, 2015, 06:58:27 am »
Agreed, but I was looking at it from the point of view that the O.P. might not be aware of the significance that a computer might have more than a single TS session active on it when attempting to basically "terminate the TS session if a certain process isn't running."  My statements were alluding towards the generalization of the methodology for a TS server, and to make it neutral w/respect to the user account that the specified process is running under, such as a case where the process was launched using "run as user" with alternate credentials having been supplied.

In its general form, the final script could rely solely on the TS extender and run as a native NT service that is capable of monitoring all active TS sessions on a TS server, or it could run in a user's session and perform the same functionality just for the users's TS session.

td

  • Tech Support
  • *****
  • Posts: 2141
    • WinBatch
Re: Script to detect running process
« Reply #6 on: February 23, 2015, 10:20:13 am »
There certainly many different approaches. A personal preference would be to use WinBatch CLR hosting, since the FCL (dotNet Framework) provides relatively easy to use classes that might eliminate the need for extenders or WMI.  But not everyone is comfortable using CLR hosting.

If the OP could start a background process in each session of interest at start-up, a simple application existence checker script might be all that is needed.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates