Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Calling all Dev's and Dot Net Heads amongst us - writing a wmi poller

Thread Tools
 
Search this Thread
 
Old 06 September 2005, 06:18 PM
  #1  
Mutts Nutts
Scooby Regular
Thread Starter
 
Mutts Nutts's Avatar
 
Join Date: May 2005
Location: AKA *Smiles* Laindon, Essex. MY04 Psuedo-STI Wagon http://swrt.verio.co.uk www.remanissradio.net
Posts: 716
Likes: 0
Received 0 Likes on 0 Posts
Question Calling all Dev's and Dot Net Heads amongst us - writing a wmi poller

Help !!!!!!!!!

having trouble plumbing some stuff together with my wmi scripts amy wmi gurus in here or people that spend way more time than is healthy in MSDN

Scenario is... I have my wmi scripts that I put together for our Sys admins that collect various bits of sys info using wmi classes (objOperatingSystem.Version; objOperatingSystem.ServicePackMinorVersion; objProcess.ProcessID; objProcess.Nameetc etc)

then collated all these into a basic hta.

The next stage that has me is getting the WITHIN Clause to work for WMI polling onder2:

i.e requests that WMI check every 10 seconds for changes that occur to instances of the Win32_LogicalDisk or Win32_Process classes . If an instance of the class is modified within the specified polling interval, a notification event is sent for each modification.

So here is extract from my code:

==========================
Sub GetProcesses

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")
strHTML = "<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
For Each objProcess in colProcesses
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td width='50%'>" & objProcess.Name & "</td>"
strHTML = strHTML & "<td width='50%'>" & objProcess.ProcessID & _

=========================================

So the 64 milliion dollar question is where do I plumb the WITHIN Clause into this.
My guess was directly after Win32_Process in the below line:

Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")

But guess I'm missing some more plumbing somewhere as it aint working.

Or even better still am I heading the wrong way up a one way strasse and there is a better way of WMI poling.

Ohhh.. one more thing ... may as well get my moneys worth out of this post

Any ideas how to turn my hta into a web service, now thats the funky stuff i want to get onto

Cheeers all
Old 06 September 2005, 08:24 PM
  #2  
David_Wallis
Scooby Regular
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Default

Hmm... pass.. do a search for WQL... however isnt it easier (messier!) to do something like..

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")

For Each objProcess in colProcesses
	wscript.echo objProcess.Name
	wscript.echo objProcess.ProcessID
Next
Set objprocess=Nothing
Set ColProcesses=Nothing

Set OSInfo = objWMIService.ExecQuery(Select * from Win32_Computer")
Blah 
Blah..

But I found this example at http://msdn.microsoft.com/library/de...g_with_wql.asp

Code:
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" _
    & strComputer & "\root\CIMV2") 
Set objEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceModificationEvent WITHIN 10 WHERE " & _
    "TargetInstance ISA 'Win32_Service'" & _
    " AND TargetInstance._Class = 'win32_TerminalService'")

i = TRUE
Do While i = TRUE
    Set strReceivedEvent = objEvents.NextEvent

    'report an event
    Wscript.Echo "An event has occurred."
Loop
See http://msdn.microsoft.com/library/de...hin_clause.asp

David
Old 06 September 2005, 10:43 PM
  #3  
Mutts Nutts
Scooby Regular
Thread Starter
 
Mutts Nutts's Avatar
 
Join Date: May 2005
Location: AKA *Smiles* Laindon, Essex. MY04 Psuedo-STI Wagon http://swrt.verio.co.uk www.remanissradio.net
Posts: 716
Likes: 0
Received 0 Likes on 0 Posts
Default

Originally Posted by David_Wallis
Cheers david that link should do the ticket, I'm missing some wql statements, should be able to work out the correct syntax and structure from that


Originally Posted by David_Wallis
Hmm pass... do a search for WQL... however isnt it easier (messier!) to do something like..
I prefer not to run scripts that echo to wScript (although they have their place) I mainly use cscript as my default WSH engine. At least in csript at least you can pipe it out to a file and make sense of the info, I hate echoing stuff in wscript, all those windows script hose boxes that you have to accept make me go .

Thats one of the reasons why I have moved most of the admin scripts into one hta and then output it to the DataArea table etc instead of the wscript.echo method and format it into tables and stuff.

Horses for courses I guess what you need your scripts to do for the task you need .

When I get past this boring/ tedious bit I can get onto the fun stuff of the web service ... I need to see if I can get an XML-RPC web service [ failing that SOAP ] not explored this bit yet.
Any good links again for this or sample snippets appreciated

let us Know if I can give anything back.. dont want to be all take, take, take

Cheers
Steve
Old 07 September 2005, 10:20 AM
  #4  
David_Wallis
Scooby Regular
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Default

Steve,

if you save that as test.vbs, and type cscript test.vbs in a cmd prompt then it will output to the command prompt window so its ok for echoing /testing

David
Old 07 September 2005, 10:55 AM
  #5  
Mutts Nutts
Scooby Regular
Thread Starter
 
Mutts Nutts's Avatar
 
Join Date: May 2005
Location: AKA *Smiles* Laindon, Essex. MY04 Psuedo-STI Wagon http://swrt.verio.co.uk www.remanissradio.net
Posts: 716
Likes: 0
Received 0 Likes on 0 Posts
Default

Originally Posted by Mutts Nutts
...I mainly use cscript as my default WSH engine....
Hi David,

I do this vice versa... sometimes its a pain that the default script host is set to wscript thats why always set my default script host to CScript, so not needing to type cscript in front of stuff.
All different ways to skin a cat i guess .

Going to trawl google for inspiration and plagerism for writing this WMI poller and a web service
Old 07 September 2005, 11:36 AM
  #6  
David_Wallis
Scooby Regular
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Default

you could just do it as an ASP page if you dont want to do it in a complicated way
Old 07 September 2005, 12:38 PM
  #7  
Mutts Nutts
Scooby Regular
Thread Starter
 
Mutts Nutts's Avatar
 
Join Date: May 2005
Location: AKA *Smiles* Laindon, Essex. MY04 Psuedo-STI Wagon http://swrt.verio.co.uk www.remanissradio.net
Posts: 716
Likes: 0
Received 0 Likes on 0 Posts
Default

Ohh if only the end user requests were that simple


Originally Posted by David_Wallis
you could just do it as an ASP page if you dont want to do it in a complicated way
Old 07 September 2005, 12:47 PM
  #8  
David_Wallis
Scooby Regular
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Default

LMFAO

Good Luck!
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Mattybr5@MB Developments
Full Cars Breaking For Spares
20
22 October 2015 06:12 AM
Danny0608
Subaru
6
27 September 2015 02:16 PM
IanG1983
Wheels, Tyres & Brakes
1
22 September 2015 09:47 PM
Saym
Was it you?
2
22 September 2015 10:18 AM
Danny0608
Subaru Parts
0
12 September 2015 02:59 PM



Quick Reply: Calling all Dev's and Dot Net Heads amongst us - writing a wmi poller



All times are GMT +1. The time now is 02:21 AM.