Which is the most efficient code

Tech-Archive recommends: Speed Up your PC by fixing your registry



Hello

Which out of the following two methods is the most efficient, I think
that the first one is the most effient because it doesn't need to
check every peice of software found, but this is just how it looks to
me, can anyone explain which is actually most efficient or if there is
a better way than the two methods below.

Code 1

strcomputer = "."
strsw = "Microsoft Visio"
set objwmiservice = getobject("winmgmts:
{impersonationlevel=impersonate}!\\" & strcomputer & "\root\cimv2")
set colSoftware = objWMIService.ExecQuery("Select * from Win32_Product
" & "Where Name = " & "'" & strsw & "'")
If colSoftware.Count > 0 Then
for each objsoftware in colsoftware
WScript.Echo objsoftware.Name
next
End If

Code 2

strcomputer = "."
Set objWMIService = GetObject("winmgmts:
{impersonationLevel=impersonate}!\\" & strcomputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery("SELECT * FROM
Win32_Product")
If colSoftware.Count > 0 Then
For Each objSoftware in colSoftware
If InStr(objsoftware.Name, "Microsoft Visio") <> 0 then
WScript.Echo objsoftware.Name
Next
End If



Thanks

Simon

.



Relevant Pages

  • Re: Which is the most efficient code
    ... for each objsoftware in colsoftware ... Set objWMIService = GetObject("winmgmts: ... Set colSoftware = objWMIService.ExecQuery("SELECT * FROM ...
    (microsoft.public.scripting.vbscript)
  • Which is the most efficient code
    ... for each objsoftware in colsoftware ... Set objWMIService = GetObject("winmgmts: ... Set colSoftware = objWMIService.ExecQuery("SELECT * FROM ...
    (microsoft.public.scripting.vbscript)
  • Re: Which is the most efficient code
    ... for each objsoftware in colsoftware ... Set objWMIService = GetObject("winmgmts: ... Set colSoftware = objWMIService.ExecQuery("SELECT * FROM ... I consider the first more efficient because a smaller recordset is ...
    (microsoft.public.scripting.vbscript)
  • Re: Which is the most efficient code
    ... In the long run stick to SQL Syntax. ... for each objsoftware in colsoftware ... Set objWMIService = GetObject("winmgmts: ... Set colSoftware = objWMIService.ExecQuery("SELECT * FROM ...
    (microsoft.public.scripting.wsh)
  • Re: Script to reboot servers.
    ... strComputer = "NameOfServer" ... Set objWMIService = GetObject("winmgmts:" _ ... I can't seem to find a way to supply the Shutdown Reason text when I call for the reboot. ...
    (microsoft.public.windows.server.scripting)