Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Total Number of Handles 1

Status
Not open for further replies.

tsdragon

Programmer
Dec 18, 2000
5,133
US
Does anyone know where the total number of handles that shows in the task manager on the performance tab comes from? Is there any way to get that number with VB? My boss needs this for a monitoring program he is working on. He says he has searched everywhere and can't find it. Help me show my boss that Tek-Tips really IS worth the time I spend on it!

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
They may be available via a WMI query, but I'm not an expert on the technology, so I'm not 100% sure.

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
check out NtQuerySystemInformation

its something ive been looking into recently for a project im working on. it "should" do what you require.


SystemProcessInformation
Returns an array of SYSTEM_PROCESS_INFORMATION structures, one for each process running in the system.
These structures contain information about the resource usage of each process, including the number of handles used by the process, the peak page-file usage, and the number of memory pages that the process has allocated.

good luck

If somethings hard to do, its not worth doing - Homer Simpson
 
WMI is where I'd look as well; here's my first stab:
Code:
[blue]Public Function GetTaskManHandles() As Long
    Dim objItem As Object ' we'll lazily late bind
    For Each objItem In GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * from Win32_PerfFormattedData_PerfProc_Process where Name='_Total'", , 48)
        GetTaskManHandles = objItem.HandleCount
    Next
End Function[/blue]
 
I'll tell him about the WMI code. We've already found out about NtQuerySystemInformation and he's been playing around with that.

strongm: Why are you setting the return value of the function inside of the for loop? Won't that just return the last value?

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Because it doesn't really matter. The 'Where' clause restricts the results to only one record, so we can set it in the loop or outside the loop. Makes no difference.
 
OIC. So the for clause is essentially just acting as an assignment statement?

strongm: My boss wants to know if you want a job (if you say yes I'm in big trouble). He just ran your code and it works perfectly! He is VERY impressed! I guess now he'll be playing around for the next few hours trying to see what other kind of information he can get that way. I think you made his whole day. You have my sincere thanks, and a star (if I could give you ten, I would). Where did you find out about WMI? He spent hours yesterday searching for information about windows handles, etc. and didn't find a single reference to WMI.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Google for ScriptoMatic2, which writes scripts for you, which are pretty easy to convert to vb6. Just concatenate a string instead of echo'ing the output to the screen, and then use a msgbox.

David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top