Results 1 to 11 of 11

Thread: [RESOLVED] Simulate Task Manager - XP

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    Resolved [RESOLVED] Simulate Task Manager - XP

    GOAL: Simulate Task Manager in windows xp.

    Problem: Cannot determine ownership of each running process.


    I can retrieve all the running processes but I cannot determine what their ownership is. Whatever is listed under "User Name" in task manager is considered the owner of the process.

    Anyone that would be able to help It would be extremely appreciated.

    Flee
    Last edited by SuperFlee; Jan 19th, 2006 at 01:26 PM.

  2. #2

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    Re: Simulate Task Manager - XP

    Anybody ??

    =(

    All these viewers and no reply's, not even super moderators.

    perhaps someone can do it in .net or c and wrap up the function calls so we can use them in vb6.

    Flee

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Simulate Task Manager - XP

    Don't know if this is what you need : http://www.vbforums.com/showpost.php...99&postcount=7


    Has someone helped you? Then you can Rate their helpful post.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    Re: Simulate Task Manager - XP

    I appreciate your help manavo11.

    I am going to research GetProcessAffinity and find out what thats about.

    Their has to be a way for the vb compiler to get the needed function to retrieve the username of each process running in memory..

    I mean c`mon, task manager does it right?

    Flee

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    Re: Simulate Task Manager - XP

    WOOHOO!!!

    I finally Solved My problem!

    This is the code that returns the ownership and other process information of all running processes in memory:

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3. Dim strComputer ' As String
    4. Dim Ret ' As Long
    5. Dim colProcesses ' As SWbemObjectSet
    6. Dim objProcess ' As SWbemObject
    7. Dim strNameOfUser ' As String
    8. strComputer = "."
    9.  
    10. Set colProcesses = GetObject("winmgmts:" & _
    11.    "{impersonationLevel=impersonate}!\\" & strComputer & _
    12.    "\root\cimv2").ExecQuery("Select * from Win32_Process")
    13.  
    14. For Each objProcess In colProcesses
    15.  
    16.     Ret = objProcess.GetOwner(strNameOfUser)
    17.     pid = objProcess.processid
    18.  
    19.     If Ret <> 0 Then
    20.         Debug.Print "Could not get owner info for process " & _
    21.             objProcess.Name & vbNewLine _
    22.             & "Error = " & Ret
    23.     Else
    24.         Debug.Print "Process " & objProcess.Name & " PID " & objProcess.processid & " is owned by " _
    25.            & "\" & strNameOfUser & "."
    26.            
    27.            
    28.     End If
    29. Next
    30.  
    31.  
    32. End Sub

    This was the results:

    VB Code:
    1. Could not get owner info for process System Idle Process
    2. Error = 2
    3. Process System PID 4 is owned by \SYSTEM.
    4. Process smss.exe PID 476 is owned by \SYSTEM.
    5. Process csrss.exe PID 524 is owned by \SYSTEM.
    6. Process winlogon.exe PID 548 is owned by \SYSTEM.
    7. Process services.exe PID 592 is owned by \SYSTEM.
    8. Process lsass.exe PID 604 is owned by \SYSTEM.
    9. Process svchost.exe PID 764 is owned by \SYSTEM.
    10. Process svchost.exe PID 840 is owned by \NETWORK SERVICE.
    11. Process svchost.exe PID 904 is owned by \SYSTEM.
    12. Process svchost.exe PID 960 is owned by \NETWORK SERVICE.
    13. Process svchost.exe PID 1020 is owned by \LOCAL SERVICE.
    14. Process spoolsv.exe PID 1200 is owned by \SYSTEM.
    15. Process GBPoll.exe PID 1476 is owned by \SYSTEM.
    16. Process inetinfo.exe PID 1508 is owned by \SYSTEM.
    17. Process Mcshield.exe PID 1560 is owned by \SYSTEM.
    18. Process VsTskMgr.exe PID 1616 is owned by \SYSTEM.
    19. Process mdm.exe PID 1704 is owned by \SYSTEM.
    20. Process nalntsrv.exe PID 1748 is owned by \SYSTEM.
    21. Process poweroff.exe PID 1804 is owned by \SYSTEM.
    22. Process PRISMXL.SYS PID 1932 is owned by \SYSTEM.
    23. Process wdfmgr.exe PID 1992 is owned by \LOCAL SERVICE.
    24. Process alg.exe PID 796 is owned by \LOCAL SERVICE.
    25. Process hkcmd.exe PID 2188 is owned by \Administrator.
    26. Process dpmw32.exe PID 2208 is owned by \Administrator.
    27. Process nwtray.exe PID 2216 is owned by \Administrator.
    28. Process Directcd.exe PID 2224 is owned by \Administrator.
    29. Process shstat.exe PID 2308 is owned by \Administrator.
    30. Process UpdaterUI.exe PID 2336 is owned by \Administrator.
    31. Process TBMon.exe PID 2348 is owned by \Administrator.
    32. Process jusched.exe PID 2368 is owned by \Administrator.
    33. Process ctfmon.exe PID 2392 is owned by \Administrator.
    34. Process AcroTray.exe PID 2592 is owned by \Administrator.
    35. Process GBTray.exe PID 2640 is owned by \Administrator.
    36. Process WBINST~1.EXE PID 3460 is owned by \Administrator.
    37. Process explorer.exe PID 2344 is owned by \Administrator.
    38. Process zone.exe PID 3776 is owned by \Administrator.
    39. Process iexplore.exe PID 1124 is owned by \Administrator.
    40. Process VB6.EXE PID 1672 is owned by \Administrator.
    41. Process wmiprvse.exe PID 2648 is owned by \NETWORK SERVICE.

    If anyone else has this issue, you now have a solution!

    Flee

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    Re: Simulate Task Manager - XP

    UPDATE:

    This is a modified version of the above code.. Its much shorter and to the point.
    VB Code:
    1. Dim PID As String
    2.     Dim PROCESS As String
    3.         Dim OWNER As Variant
    4.         Dim objProcess As Variant
    5.         Dim colProcesses As Variant
    6.                      
    7.     Set colProcesses = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").ExecQuery("Select * from Win32_Process")
    8.    
    9.     For Each objProcess In colProcesses
    10.         If objProcess.GetOwner(OWNER) = 0 Then
    11.             PROCESS = objProcess.Name
    12.             PID = objProcess.processid
    13.             debug.print PID & " " & PROCESS & " " & OWNER
    14.         End If
    15.     Next

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Simulate Task Manager - XP

    Nice job. This is worth booking marking!

  8. #8
    New Member
    Join Date
    Mar 2006
    Posts
    2

    Re: [RESOLVED] Simulate Task Manager - XP

    I like these and find them useful but am a little confused about the code. Where does the variable OWNER (or strNameOfUser) get set? I ran the code and it works but do not know how these are being set.

    Thanks

  9. #9
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: [RESOLVED] Simulate Task Manager - XP

    It gets set when this is executed : objProcess.GetOwner(OWNER)


    Has someone helped you? Then you can Rate their helpful post.

  10. #10
    New Member
    Join Date
    Mar 2006
    Posts
    2

    Re: [RESOLVED] Simulate Task Manager - XP

    After I posted I figured as much. When I program I hardly ever send actual objects from one method to another so it didn't appear to me that that was happening at first.

    I would assume it would of been better for them to have had the owner as a property and not the result of a method of the object. For example,
    Code:
    OWNER = objProcess.Owner
    If OWNER = 0 Then
       ...
    End If

  11. #11
    Lively Member fifo's Avatar
    Join Date
    Dec 2005
    Location
    HaiPhong, Vietnam
    Posts
    77

    Re: [RESOLVED] Simulate Task Manager - XP

    nice, so cool
    !Have fun!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width