lcty Posted September 10, 2013 Share Posted September 10, 2013 Hi guys, I'm trying to query a service's status on a remote computer using the WMI. That's what I have so far: Func getServiceState() $name = "myServer" Dim $obj_WMIService = ObjGet("winmgmts:{impersonationLevel=impersonate,authenticationLevel=PktPrivacy}!" & $name & "rootcimv2") If (IsObj($Obj_WMIService)) And (Not @error) Then ;Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_Service where Name = "dhcp"') Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_Service') Local $Obj_Item For $Obj_Item In $Col_Items ConsoleWrite($Obj_Item.Status & @CRLF) Next Else ConsoleWrite(@error) EndIf EndFunc (please excuse the code box didn't work for me today :/) It works fine with workstations but with servers (especially Server 2003) I receive an Error 0. Anyone of you familiar with that interface and knows what I'm doing wrong? I would be very thankful for your answers! Best reagards lcty Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 10, 2013 Moderators Share Posted September 10, 2013 Hi, Icty. You have to ensure your account has privileges over WMI on the server. This works just fine for me on both workstations and servers (2k8R2): $sServer = "WIN-U8GBUDPJ2O6" $wbemFlagReturnImmediately = "&h10" $wbemFlagForwardOnly = "&h20" $WMI = ObjGet("winmgmts:\\" & $sServer & "\root\CIMV2") $aItems = $WMI.ExecQuery("SELECT * FROM Win32_Service", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) For $element in $aItems MsgBox(0, "", "Name: " & $element.Name) Next "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
water Posted September 10, 2013 Share Posted September 10, 2013 Search the Examples forum for "Scriptomatic". This script generates WMI AutoIt code for you. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
trancexx Posted September 10, 2013 Share Posted September 10, 2013 JLogan3o13 you are actually setting wbemFlagBidirectional flag for the query because you defined wrong the other two flags. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 10, 2013 Moderators Share Posted September 10, 2013 (edited) Can you elaborate? The way I set the other two flags is how it is done in the AutoIt version of Scriptomatic, as well as the original Microsoft version, as well as the Microsoft documentation online. No problem fixing it if I am wrong, just curious why it is wrong Edit: My mistake, in the AutoIt version they are set to 0x10 and 0x20 respectively, although I believe this is categorically equal to what I have. Edited September 10, 2013 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
trancexx Posted September 10, 2013 Share Posted September 10, 2013 (edited) Then they are all wrong.wbemFlagReturnImmediately is 0x10 and wbemFlagForwardOnly is 0x20.If you define former as "&h10" and later as "&h20" then when you do:$wbemFlagReturnImmediately + $wbemFlagForwardOnly...you get 0. That's the value of wbemFlagBidirectional or wbemFlagReturnWhenComplete if you wish. Edited September 10, 2013 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 10, 2013 Moderators Share Posted September 10, 2013 That is a lot of people wrong Thanks for the input. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
trancexx Posted September 10, 2013 Share Posted September 10, 2013 That is a lot of people wrong Thanks for the input.It's actually only you. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 10, 2013 Moderators Share Posted September 10, 2013 That's okay, I've been married long enough to be used to being told I'm wrong - you learn to just smile and nod and let them feel like they're right. Edit: Last hijacking of this thread by me "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! 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