Jump to content
  • Advertisement
Sign in to follow this  
Portishead

[C#] Working with processes.

This topic is 3616 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is the first time I'm working with List View, and I'm trying to do a Mini Task Manager. [Just for learning, not anything special] Edit: List View's problem for now are solved, thanks snisarenko for helping. :) I have a new problem with showing the processes (in the lat comment). Thanks in advance for the helpers. :) Portishead. [Edited by - Portishead on December 22, 2008 5:21:23 PM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Portishead
Another thing I saw is when I click on one of the rows in the list, it selects it, but when I click on a button the select goes off. If I want to use the button to do something with selected row, will it still get the selected row? And how to I find out which row\rows were selected?


Set the "ListView.HideSelection" property to "false" to leave the selection visible after ListView loses focus.

Set the "ListView.MultiSelect" property to "false" if you want only one item selected at a time.

Use the "ListView.SelectedIndices" or "ListView.SelectedItems" to obtain selected row indices/items.



If you need more info on the ListView control use the MSDN Reference


Share this post


Link to post
Share on other sites
Thanks. :)
I'll try to see how I work it out now.

I have a question, not exactly related to programing, but what's the difference between a process and a task? How can I notice the difference through the code?

Share this post


Link to post
Share on other sites
Quote:
Original post by Portishead
I have a question, not exactly related to programing, but what's the difference between a process and a task? How can I notice the difference through the code?


Don't quote me on this, but I think the windows task manager identifies "tasks" as currently active windows that were created by some process.

As far as getting information about currently running processes and windows, you are going to have to dig through the Win 32 API. But I'll give you some starting points
Win32 Process and Thread Functions
Win32 Window Functions

If you want to access Win 32 API functions from C#, you are going to have to use P/Invoke.
Tutorial 1
Tutorial 2
Tutorial 3
PInvoke Reference

Share this post


Link to post
Share on other sites
Thanks. :)

I have a problem with TotalProcessorTime and StartTime.
For somehow, it gives me an error - "acces denied". How can I solve this error? What's wrong with those?

Share this post


Link to post
Share on other sites
Quote:
Original post by Portishead
Thanks. :)

I have a problem with TotalProcessorTime and StartTime.
For somehow, it gives me an error - "acces denied". How can I solve this error? What's wrong with those?

what's the exception msg?
Are you ruuning it from your local drive? from desktop or any other folder other inside "C:\Documents and Settings\<user>\Desktop"? Or you are probing the remote server processes? If later case, you might need impersonation .

Otherwise, something like this will do:

Dim p As Process

p = CType(processes.Item(processId), Process)
' Get the most current data
p.Refresh()

' Get the process detail
EnumProcess(p)
' Get the thread detail
EnumThreads(p)

where EnumProcess(p):

Dim valuePairs()() As Object = { _
New Object() {"Start Time", p.StartTime.ToLongDateString() & " " & p.StartTime.ToLongTimeString(), ""}, _
New Object() {"Responding", p.Responding, ""}, _
New Object() {"Handle", p.Handle, ""}, _
New Object() {"Handle Count", p.HandleCount, "N0"}, _
New Object() {"Main Window Handle", p.MainWindowHandle, ""}, _
New Object() {"Main Window Title", p.MainWindowTitle, ""}, _
New Object() {"Module Count", p.Modules.Count, "N0"}, _
New Object() {"Base Priority", p.BasePriority, ""}, _
New Object() {"Working Set", p.WorkingSet64, "N0"}, _
New Object() {"Peak Working Set", p.PeakWorkingSet64, "N0"}, _
New Object() {"Private Memory Size", p.PrivateMemorySize64, "N0"}, _
New Object() {"Nonpaged System Memory Size", p.NonpagedSystemMemorySize64, "N0"}, _
New Object() {"Paged Memory Size", p.PagedMemorySize64, "N0"}, _
New Object() {"Peak Paged Memory Size", p.PeakPagedMemorySize64, "N0"}, _
New Object() {"Virtual Memory Size", p.VirtualMemorySize64, "N0"}, _
New Object() {"Peak Virtual Memory Size", p.PeakVirtualMemorySize64, "N0"}, _
New Object() {"Priority Boost Enabled", p.PriorityBoostEnabled, ""}, _
New Object() {"Priority Class", p.PriorityClass, ""}, _
New Object() {"Processor Affinity", p.ProcessorAffinity.ToInt32, ""}, _
New Object() {"Thread Count", p.Threads.Count, ""}, _
New Object() {"Min Working Set", p.MinWorkingSet.ToInt32, "N0"}, _
New Object() {"Max Working Set", p.MaxWorkingSet.ToInt32, "N0"}, _
New Object() {"Main Module", IIf(p.MainModule Is Nothing, "", p.MainModule.ModuleName), ""}}

Me.AddPairs(valuePairs)

In your VS installation path (C:\Program Files\Microsoft Visual Studio 9.0\Samples\1033\VBSamples.zip), there's one sample called "process viewer". Maybe you can try on that one. Else you might need to download from here: Visual Basic 2008 Samples


Share this post


Link to post
Share on other sites
Yeah, I'm running it from a folder that starts with "C:\Documents and Settings\<user>\".. My documens -> Visual Studios folder.

I program in C# and CType does not exist in the Process functions. Do I need to download anything for it? [What you gave is for VB]

Share this post


Link to post
Share on other sites
Quote:
Original post by Portishead
Yeah, I'm running it from a folder that starts with "C:\Documents and Settings\<user>\".. My documens -> Visual Studios folder.

Are you using Vista? or VS2008? VS2005 SP1? I thought u opne from there will prompt you some warning msg? Can try run in a folder under C:\bin ? Or run VS as admin if using Vista?

Quote:
Original post by Portishead
I program in C# and CType does not exist in the Process functions. Do I need to download anything for it? [What you gave is for VB]

CType is basically some sort of type-cast.

using Web service from developerfusion, give me this:
p == (Process)processes.Item(processId)

Share this post


Link to post
Share on other sites
go to: Help>About>Installed product.

Have you tried running/debugging under under C:\bin ? running VS2008 sample?Else post your sample code.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!