Jump to content

Trying to create a new instance in object.


Digisoul
 Share

Recommended Posts

Hello there,

I am working an application which automatically sets the status for CALM-AV in Windows Security Center.

Now my question is why its giving error when i tried to create the new instance ?

$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\SecurityCenter:AntiVirusProduct").Spawninstance_

thanks in advance.

73 108 111 118 101 65 117 116 111 105 116

Link to comment
Share on other sites

Hello there,

I am working an application which automatically sets the status for CALM-AV in Windows Security Center.

Now my question is why its giving error when i tried to create the new instance ?

$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\SecurityCenter:AntiVirusProduct").Spawninstance_
thanks in advance.
Get the object reference before trying to use methods of it:
$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & _
        "\root\SecurityCenter:AntiVirusProduct" )

If IsObj($oWMI) Then
    ConsoleWrite("$oWMI is object: " & ObjName($oWMI) & @LF)
Else
    ConsoleWrite("$oWMI is not an object." & @LF)
EndIf

$oWMI.Spawninstance

$oWMI = ""

If you get errors from calling the method, add a COM error handler to see what's up.

:D

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Get the object reference before trying to use methods of it:

$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & _
        "\root\SecurityCenter:AntiVirusProduct" )

If IsObj($oWMI) Then
    ConsoleWrite("$oWMI is object: " & ObjName($oWMI) & @LF)
Else
    ConsoleWrite("$oWMI is not an object." & @LF)
EndIf

$oWMI.Spawninstance

$oWMI = ""

If you get errors from calling the method, add a COM error handler to see what's up.

:D

Thanks,

I just use this method and its work well

$oAntiVirusProduct = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\SecurityCenter:AntiVirusProduct")   
If Not @error Then $nAntiVirusProduct = $oAntiVirusProduct.Spawninstance_

Will you please tell me the reason ?

Edited by Digisoul

73 108 111 118 101 65 117 116 111 105 116

Link to comment
Share on other sites

Thanks,

I just use this method and its work well

$oAntiVirusProduct = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\SecurityCenter:AntiVirusProduct")   
If Not @error Then $nAntiVirusProduct = $oAntiVirusProduct.Spawninstance_

Will you please tell me the reason ?

First you got the object reference, then you called the method. That's how it's supposed to work.

In the OP you tried to call the method directly off ObjGet(). It just doesn't work that way.

:D

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...