Jump to content

Recommended Posts

Posted

I need to deploy a script that tests for existence of prg1 on the client and if true then run PRG2 (used to kill the process of PRG1) if false, do nothing.

the script is to be deployed as a login script to XP clients in 2000 server domain. The script needs to check every 15 seconds while the user is logged on.

summary: check for one process, if it exists kill another.

Any ideas?

Thanks.

chaneu


Posted

Something like this should work for you. Found in the scriptcenter repository, http://www.microsoft.com/technet/scriptcen...t.mspx?mfr=true

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colMonitoredProcesses = objWMIService. _
ExecNotificationQuery("select * from __instancecreationevent " _
& " within 1 where TargetInstance isa 'Win32_Process'")
i = 0

Do While i = 0
Set objLatestProcess = colMonitoredProcesses.NextEvent
If objLatestProcess.TargetInstance.Name = "notepad.exe" Then
objLatestProcess.TargetInstance.Terminate
End If
Loop

This monitors the processes being created looking specifically for 'notepad.exe' and when it finds it terminates the 'notepad.exe' process. If you want it to run something else replace 'objLatestProcess.TargetInstance.Terminate' with the appropriate code.

NOTE: If running this from a login script either put it at the end of the script, or run it as its own script as it will never exit from the loop so the script will never terminate.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...