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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

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
sirbountyCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.