Check if WQL __InstanceCreation query returns results
-
יום שישי 20 אפריל 2012 09:21
Hello, how can write code that can check if __InstanceCreation query has returned rows or not. I'm using this code to check for the creation of a filePrivate Function CheckForFileCreation() As Boolean Try Dim query1 As New WqlEventQuery( _ "SELECT * FROM __InstanceCreationEvent WITHIN 2 WHERE " & _ "TargetInstance ISA 'CIM_DataFile' and " & _ "TargetInstance.Name='" & bookingFile & "'") Dim watcher1 As New ManagementEventWatcher(query1) Console.WriteLine("Waiting for file booking 1") Dim eventObj1 As ManagementBaseObject = watcher1.WaitForNextEvent() 'Cancel the event subscription 'watcher1.Stop() 'Console.WriteLine("Files Found") Catch err As ManagementException Console.WriteLine(err.Message) End Try End Functionso I need to know if the query returned > 0 rows, if it did then the function will return true, if the query returned 0 rows then the function should return false. Sorry I am a complete noob with WMI and WQL
כל התגובות
-
יום שני 23 אפריל 2012 05:38מנחה דיון
Hi airwalker2000,
Welcome to the MSDN forum.
I assume you have known the meaning of this application. So if you want’s know whether the query have return the records, you can simply return the True out of the function if the watcher1 found record. You can set a timeout value to the water1.If nothing happened after the water1 ended, set the False to the return value.
Hope this helps.
Mark Liu-lxf [MSFT]
MSDN Community Support | Feedback to us
- סומן כתשובה על-ידי Mark Liu-lxfModerator יום שלישי 01 מאי 2012 05:52
-
יום שלישי 01 מאי 2012 05:52מנחה דיון
Hi airwalker2000,
We haven’t heard from you for several days. I’d like to mark my reply as answer firstly. If you have any additional questions, you also can unmark the replay and post your question here.
Sorry for any inconvenience and have a nice day.
Mark Liu-lxf [MSFT]
MSDN Community Support | Feedback to us