?
Solved

do not allow process

Posted on 2008-11-13
13
Medium Priority
?
221 Views
Last Modified: 2012-05-05
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




0
Comment
Question by:ankur3020
  • 6
  • 6
13 Comments
 
LVL 7

Expert Comment

by:knightfox
ID: 22949041
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 22949126
Why not remove rights for the user to run those three apps?
0
 

Author Comment

by:ankur3020
ID: 22951181
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 67

Expert Comment

by:sirbounty
ID: 22951506
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
 

Author Comment

by:ankur3020
ID: 22951693
getting error in line 11. at objproc.targetinstance.name
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 22951783
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
 

Author Comment

by:ankur3020
ID: 22951902
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 22952671
not sure what you mean...
0
 

Author Comment

by:ankur3020
ID: 22957301
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 22958921
Just add it to the array on line 1:

arrProcesses = Array("googletalk.exe", "msnmgr.exe","yahoomsg.exe","yahoomessenger.exe")
0
 

Author Comment

by:ankur3020
ID: 22959028
ok, thanks
0
 

Author Closing Comment

by:ankur3020
ID: 31516332
good
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22959539
Happy to help - thanx for the grade! :^)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question