Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBS Script Killing Excel Process

Status
Not open for further replies.

maccten2000

Programmer
May 13, 2003
37
EU
Hello All,

I have a VB script which deals in Processes. Basically we are using a third party application that allows you to interact with the Excel object but refuses to kill the object once it has quit excel. I have founda VBS script to fix this problem but would like someone to tell me the error in the code and perhaps if you have the time explain to me the second line and the variables it is taking

The code is

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersona te}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'EXCEL.EXE'")
Dim Counter
Counter = 0
For Each objProcess in colProcessList
Counter = Counter +1
if Counter = colProcessList.count Then
objProcess.Terminate()
End if
Next

Thanks for your time
 
unless i am mistaken this will only kill the last excel.exe process that it finds, e.g. if there are 2 excel.exe's running it will kill the second one, if there are 3 running it will kill the 3rd. the last one being the one what WMI returns in its collection of Win32_Process's.

for me the error in your script is the white space in the 'impersona te'?

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
Hi MrMovie,

Thanks very much for your feedback
I have fixed the syntax error you have pointed out but i have another error at line 7 Char 19 where it is expecting an end of Statement.

I have put in a ; but that doesnt4 seem to make a difference

I was wondering if you could see the issue.
I apologize if this seems like a rookie mistake but i have only just started VBS and there is a lot to go through

Thanks
 
i dont know where line 7 is.
a ; is not a line end chr in vbscript (powershell maybe)

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top