-3

Excuse me for this - there's an issue with this code - it's from

https://www.alexandreviot.net/2014/10/03/configmgr-2012-application-detection-method-for-software-update/#comment-40712

I don't normally use VB i use PS and have tried various things editing line 7 of this code which is:

Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &strComputer & "\root\cimv2")

With no success. Can anyone help here? This might be quite easy for someone - this would help me use vb as a detection clause for older hardware which doesn't run the windows management framework/powershell.

'Returns if Windows KB2506143 installed
    Option Explicit
    Dim objWMI, strComputer
    strComputer = "."

    'Run the query
    Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &strComputer & "\root\cimv2")

    Dim listPatches
    Dim patch
    Set listPatches = objWMI.ExecQuery ("Select * from win32_QuickFixEngineering where HotFixID like 'KB960568'")
    For Each patch in listPatches
    Wscript.echo "Update installed"
    Next
    WScript.Quit


    C:\Users\royston\AppData\Local\Adersoft\VbsEdit\Temp\BCAWFOZT.vbs(7, 76) Microsoft VBScript compilation error: Expected ')'


    ***** script completed - exit code: 1 *****

Thanks in advance.

Royston
  • 433
  • 2
  • 9
  • 25
  • 3
    You have html entities included in the code. `&` = `&` , so you should use `... & strComputer & ...` , being `&` the standard concatenation operator – MC ND Nov 09 '18 at 09:35

1 Answers1

3

This is probably just a problem with pasting code into whatever that site uses for interpreting it. It should say

Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

but as this is really somewhat of a pet peeve of mine I wanna add that the whole concept of using strComputer when not used as a variable is really useless. I know it is done in every example on the web but if you want to run wmi locally and not remotely just use

Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

and drop the strComputer = "." line. There is really no need to make scripts harder to read when the variable is used like a constant.

Syberdoor
  • 2,521
  • 1
  • 11
  • 14
  • Thank you Syberdoor for bringing up the extraneous use of a strComputer variable! That's also a pet peeve of mine. – Paul G Nov 22 '18 at 17:54