Solved

Cancel WMI query while it is in process? (because it hangs)

Posted on 2008-10-06
19
1,076 Views
Last Modified: 2012-06-27
I'm doing some WMI queries on about 3000 machines.  The problem is, some of those machines are in a hung state and when I do the query, the ASP script just locks up indefinitely.  The only fix is restarting IIS.  I am using win32_pingstatus before I do the queries to determine if the server is online.  The servers in question respond saying they are online, but any following WMI queries cause the process to hang.  What I need to know is a good way to detect when this has happened and continue to the next server in the loop.
0
Comment
Question by:Cerixus
  • 7
  • 5
  • 4
  • +1
19 Comments
 
LVL 1

Author Comment

by:Cerixus
ID: 22656456
Reading some other solutions, I saw someone recommend launching the query in a separate process or thread and then ending the process/thread after 5 seconds or something.  How hard is that to do?  It would be an acceptable answer.
0
 
LVL 5

Expert Comment

by:sciphre
ID: 22661881
You could try "net use \\fqdn" and check the return status of that instead of ping, this wouldn't actually stop all queries from hanging, but it would greatly reduce the number of false positives in your alive check.
0
 
LVL 1

Author Comment

by:Cerixus
ID: 22663239
I tried NET USE on 3 different servers.  One known good Windows, one known Linux and one known to be locked up Windows.  All three responded with "The command completed successfully."
0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 200 total points
ID: 22663920
I don't really know a way to do that in ASP.  It isn't something that can open seperate processes.  Now you could have some custom object that would do this and then it would stop and return a result after a specified period.  ASP can't kill it though.  The part that stops it would have to be what ASP executes.
Developing a custom object for ASP is not my expertise so I am not sure how easy it would be or if it will offer the solution you want.  I can say that if you are on a shared server it probably won't be something you can pursue since the web host provider will most likely not allow you to add it.
Let me know how this helps or what other info you may need.
bol
0
 
LVL 1

Author Comment

by:Cerixus
ID: 22663942
Creating a separate process was just an additional thought.  What I really want, and what I would think should be TOTALLY possible, is a way to detect how long the WMI query has been running, or even a particular ASP function, and break out of it.
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 200 total points
ID: 22664595
You mentioned that you have some Linux machines....against Windows machines, WMI connection attempts should automatically time-out, but I'm not sure about windows.....what you could do, is check for the existence of the C$ admin share of a Windows machine, so you know it's Windows.....

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If Ping(strComputer) = True Then
   If objFSO.FolderExists(strComputer & "\C$") = True Then
      ' execute WMI query
   Else
      Respone.Write "Not a Windows machine"
   End If
Else
   Response.Write "Ping failed for " & strComputer
End If


Regards,

Rob.
0
 
LVL 54

Assisted Solution

by:b0lsc0tt
b0lsc0tt earned 200 total points
ID: 22664730
What I really want, and what I would think should be TOTALLY possible, is a way to detect how long the WMI query has been running, or even a particular ASP function, and break out of it.
Just in response to the above I wanted to clarify that in ASP that is not possible.  At least to my knowledge.  The script itself has timeouts and there are error objects, etc but ASP doesn't have a way to kill a process you started or even see it status.  In almost all cases the script will just hold until the process is done and so that is why you have the issue.  This is why I said a solution to the problem will need to be in the object, which will timeout or "monitor" the process to keep things in ASP moving.
The above is one of the reasons I have heard ASP opponents say it isn't a programming or web development language at all.  I like ASP and use it often but it does have limits and what I quoted above is one.
bol
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22664826
Also, as it's usually the GetObject calls that hangs, such as:
      strComputer = "pcname"
      Set objWMIService = GetObject("winmgmts:" _
          & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

the GetObject method does not support any configurable time-out setting:
http://msdn.microsoft.com/en-us/library/8ywk619w(VS.85).aspx

Regards,

Rob.
0
 
LVL 5

Assisted Solution

by:sciphre
sciphre earned 100 total points
ID: 22666729
Caveat: I have never written a single line of ASP

ASP does appear to support multithreading: http://www.beansoftware.com/ASP.NET-Tutorials/Manual-Synchronize-Thread.aspx
There's an easier way also described on that page, but that doesn't allow control over the resulting thread.

Try implementing something similar to this (aka a watchdog):

Get request from client to do a WMI query
Check if the client already has a query submitted? Submit query and poke a GUID for it into the db : fail and warn client about running task
Start a manual background thread for the WMI query
Start a loop in the main thread that checks for completion every say 5 seconds and expires after 2 minutes. On expiry run Thread.Abort() and clean GUID. On completion fetch the result and display it, then clean GUID. Optionally store result in db by GUID instead of clearing it.

This may or may not cancel the WMI query, but it could be your solution - two issues though - you might have a parallel scalability problem, as you're now using two threads for one, and you might have processes hanging instead of dying. Test throughly.
Also note that thread programming is difficult - try to keep interactions between threads to start/check/stop and return.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 22671114
sciphre,
ASP.NET is a completely different technology and framework than ASP (classic).  I may have been wrong and assumed this wasn't .NET so the Asker should clarify this but the article you found won't help if this isn't .NET.  Indeed .NET does support what you say and probably could stop the process.  Unfortunately you can't use both on a page (Classic and .NET) so it would mean a complete rewrite if this is Classic ASP.
Thanks for posting in case I did make a mistake.  My comments were all about Classic ASP.  It seems like you are new here but off to an impressive start.  :)  Good job and thanks for your help and time with the members.
bol
p.s.  I'm glad you mentioned your experience level on this.  Nice thing to see in a case like this.
0
 
LVL 1

Author Comment

by:Cerixus
ID: 22671492
It is classic ASP.
0
 
LVL 5

Expert Comment

by:sciphre
ID: 22671998
My apologies - For reasons that are lost to me now Classic ASP was marked in my mind with red, wide, "don't go there" sticky tape a few years back, never really crossed my mind that this wasn't .Net. Call me an elitist jerk :)
I'll remove myself from this conversation.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22725435
Hi, were you able to try the
     If objFSO.FolderExists(strComputer & "\C$") = True Then
method?

Regards,

Rob.
0
 
LVL 1

Author Comment

by:Cerixus
ID: 22758978
RobSampson:
I have not specifically tried that, but since it IS able to initially connect to the server, I'm assuming it will be able to connect to the administrative share for the C drive.  But, the WMI query would still stall.
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 200 total points
ID: 22762901
Hmmm...the main problem (as you've discovered) is that during a WMI query, there is no way to interrupt the process, nor is there a configurable time-out value.

I have never used this approach, but you should be able to use Asynchronous Event Notifications:
http://msdn.microsoft.com/en-us/library/aa393011(VS.85).aspx

Regards,

Rob.
0
 
LVL 1

Author Comment

by:Cerixus
ID: 22933446
I had a thought... is it possible to query something ELSE to see if I get a response, then execute my query based on that?  Like say the Server service?  Is there any way I could programmatically see if it responds?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22945268
Well, not really, because with VBScript, that would still require a WMI connection....

So you'd have to look at a DOS tool, which *might* return quicker, but seeing as it wouldn't use WMI to connect, then even if that were successful, there's still a possibility that the WMI connection could have problems.  That's why Microsoft have a WMI Diagnostics tool (which cannot be run remotely).

Did you try the C$ share approach?

Regards,

Rob.
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

If Ping(strComputer) = True Then

   If objFSO.FolderExists(strComputer & "\C$") = True Then

      ' execute WMI query

   Else

      Respone.Write "Not a Windows machine"

   End If

Else

   Response.Write "Ping failed for " & strComputer

End If

Open in new window

0
 
LVL 1

Author Closing Comment

by:Cerixus
ID: 31503704
Rewriting entire site in .net
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 23207729
I'm glad I could help a bit.  Thanks for the fun question, the grade and the points.
bol
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now