Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1147
  • Last Modified:

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

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
Cerixus
Asked:
Cerixus
  • 7
  • 5
  • 4
  • +1
5 Solutions
 
CerixusAuthor Commented:
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
 
sciphreCommented:
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
 
CerixusAuthor Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
b0lsc0ttCommented:
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
 
CerixusAuthor Commented:
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
 
RobSampsonCommented:
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
 
b0lsc0ttCommented:
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
 
RobSampsonCommented:
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
 
sciphreCommented:
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
 
b0lsc0ttCommented:
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
 
CerixusAuthor Commented:
It is classic ASP.
0
 
sciphreCommented:
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
 
RobSampsonCommented:
Hi, were you able to try the
     If objFSO.FolderExists(strComputer & "\C$") = True Then
method?

Regards,

Rob.
0
 
CerixusAuthor Commented:
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
 
RobSampsonCommented:
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
 
CerixusAuthor Commented:
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
 
RobSampsonCommented:
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
 
CerixusAuthor Commented:
Rewriting entire site in .net
0
 
b0lsc0ttCommented:
I'm glad I could help a bit.  Thanks for the fun question, the grade and the points.
bol
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now