do not allow process

suppose after system start at any time there are 37 processes running in task manager. What vbs code i should run which stop running of 3 specified processes. i.e. when ever user try to run these three, it terminated automatically.  the three processes will be :

yahoo messenger
msn messenger and
gtalk




ankur3020Asked:
Who is Participating?
 
sirbountyConnect With a Mentor Commented:
Try this version:
arrProcesses = Array("googletalk.exe", "msnmgr.exe","yahoomsg.exe")
 
Dim objWMI : Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
Dim colProcs : Set colProcs = objWMI. ExecNotificationQuery ("Select * From __InstanceCreationEvent Within 5 Where TargetInstance ISA 'Win32_Process'")
x = 0
Do While i = 0
    Set objProc = colProcs.NextEvent
    strProcessName = LCase(objProc.TargetInstance.Name)
    intPID =  objProc.TargetInstance.ProcessID 
    For Each strItem in arrProcesses
        If strItem = strProcessName Then
          Set colProcessList = objWMI.ExecQuery ("Select * from Win32_Process Where ProcessID = " & intPID & "")
          For Each strProc in colProcessList
            strProc.Terminate()
          Next
        End If
    Next
Loop

Open in new window

0
 
knightfoxCommented:
Try this...

I think the process names are correct but you can change them if they are not..

Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
strComputer = "."
strProcessKill1 = "'yahoomsg.exe'"
strProcessKill2 = "'msnmsgr.exe'"
strProcessKill3 = "'googletalk.exe '"  

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcessKill1 )
For Each objProcess in colProcess
   objProcess.Terminate()
Next

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcessKill2 )
For Each objProcess in colProcess
   objProcess.Terminate()
Next

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcessKill3 )
For Each objProcess in colProcess
   objProcess.Terminate()
Next


/Fox
0
 
sirbountyCommented:
Why not remove rights for the user to run those three apps?
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
ankur3020Author Commented:
code is ok, but running in reverse direction. i.e. if i open yahoo, it opens and when i run code , vbs file close yahoo. but i want inverse.

i.e. i run vbs code first and then the code keep eye on processes and do not allow specified processes to start. please amend as required.
0
 
sirbountyCommented:
This should do it...(but I still think yanking permissions is the better route... ;^)
arrProcesses = Array("googletalk.exe", "msnmgr.exe","yahoomsg.exe")
 
Dim objWMI : Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
Dim colProcs : Set colProcs = objWMI. ExecNotificationQuery ("Select * From __InstanceCreationEvent Within 5 Where TargetInstance ISA 'Win32_Process'")
x = 0
Do While i = 0
    Set objProc = colProcs.NextEvent
    strProcessName = LCase(objProc.TargetInstance.Name)
 
    For Each strItem in arrProcesses
        If strItem = strProcessName Then objProc.Terminate()
    Next
Loop

Open in new window

0
 
ankur3020Author Commented:
getting error in line 11. at objproc.targetinstance.name
0
 
ankur3020Author Commented:
it is working fine. thanks. can u little amend the code so that it stop running all processes that start with yahoo word. rest two will be same . of course if u do not mind to amend.
0
 
sirbountyCommented:
not sure what you mean...
0
 
ankur3020Author Commented:
i mean, in old yahoo , the name is yahoomsg but in new yahoo 9, it is yahoomessenger, so in instead of writing full name , can i do some thing which can stop running of all processes start with yahoo word like yahoo*.exe .
0
 
sirbountyCommented:
Just add it to the array on line 1:

arrProcesses = Array("googletalk.exe", "msnmgr.exe","yahoomsg.exe","yahoomessenger.exe")
0
 
ankur3020Author Commented:
ok, thanks
0
 
ankur3020Author Commented:
good
0
 
sirbountyCommented:
Happy to help - thanx for the grade! :^)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.