Torgeir
Thu Sep 09 16:33:50 CDT 2004
Tony Pedretti wrote:
> Torgeir,
>
> Thanks for the references.
> I've taken them and with other sources produced the following script.
>
> One last improvement I'd like to make is to have the array loop be dynamic.
> That is I've found I can't increment the Do Until against the array (aryProcess) until its
> value is NULL or "". The scripts just errors since position (6) doesn't exist to test
> against.
>
> I'd like to have the test condition read something to the effect of...
> Do Until aryProcess(intArrayNumber) = NULL
>
> Anyone have any suggestions?
Hi
To get the number of elements in an array (note that array
counts start at 0):
'--------------------8<----------------------
aryProcess = Array("aaaaaaaa.exe", "bbbbbbb.exe", "cccccccc.exe", _
"xxxxx.exe", "yyyyyy.exe", "zzzzzzz.exe")
WScript.Echo UBound(aryProcess)
'--------------------8<----------------------
But it is much easier to use this:
For Each strProcess In aryProcess
WScript.Echo strProcess
Next
like here:
'--------------------8<----------------------
aryProcess = Array("aaaaaaaa.exe", "bbbbbbb.exe", "cccccccc.exe", _
"xxxxx.exe", "yyyyyy.exe", "zzzzzzz.exe")
'(snip other code)
strComputer = "."
Set objWMIservice = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
For Each strProcess In aryProcess
Set colProcessList = objWMIservice.ExecQuery _
("SELECT * from Win32_Process WHERE Name = '" & strProcess & "'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
Next
'--------------------8<----------------------
--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx