Digisoul Posted September 6, 2009 Share Posted September 6, 2009 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 More sharing options...
PsaltyDS Posted September 6, 2009 Share Posted September 6, 2009 (edited) 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. Edited September 6, 2009 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 More sharing options...
Digisoul Posted September 6, 2009 Author Share Posted September 6, 2009 (edited) 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. 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 September 6, 2009 by Digisoul 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 7, 2009 Share Posted September 7, 2009 (edited) 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. Edited September 7, 2009 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now