Results 1 to 11 of 11

Thread: How to know which running process is a system process

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    168

    Question How to know which running process is a system process

    I have a piece of code which gives me the list of currently running processes in vb. Know I want to sort those processes according to their type for example : system processes seperatly etc.

    Any ideas on this?
    Regards,

    Piyush


    Nothing is Impossible because the word impossible itself says I'mpossible

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    168

    Re: How to know which running process is a system process

    By list of running processes I mean all processes which are running currently on windows.
    Regards,

    Piyush


    Nothing is Impossible because the word impossible itself says I'mpossible

  3. #3
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: How to know which running process is a system process

    I'm not expert on this, but running Task Manager in XP allows you to list the "User Name" for each process. I notice that several of these are named "SYSTEM", others are named "LOCAL SERVICE", etc.

    Does your code return the User Name? Can you use it for what you want to do?
    This world is not my home. I'm just passing through.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    168

    Re: How to know which running process is a system process

    I thought that but what if I can create a windows service and run it under system acoount so the username is managed and it always shows system.
    Regards,

    Piyush


    Nothing is Impossible because the word impossible itself says I'mpossible

  5. #5
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: How to know which running process is a system process

    I thought that but what if I can create a windows service and run it under system acoount so the username is managed and it always shows system.
    Well, I'm really making it up as I go along now, but isn't that the definition of a system process? I don't know. Maybe you'd better hope that someone else jumps in on this thread.
    This world is not my home. I'm just passing through.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    168

    Smile Re: How to know which running process is a system process

    Some one tell me how to use GetProcessAffinityMask function.
    Regards,

    Piyush


    Nothing is Impossible because the word impossible itself says I'mpossible

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

    Re: How to know which running process is a system process

    Quote Originally Posted by pbuddy_8
    Some one tell me how to use GetProcessAffinityMask function.
    After spending some time Googling, I saw no examples of using:

    GetProcessAffinityMask
    SetProcessAffinityMask
    SetThreadAffinityMask

    with VB. I did, however, find some examples using C++. Are you familiar with that language?

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    168

    Re: How to know which running process is a system process

    ack No
    Regards,

    Piyush


    Nothing is Impossible because the word impossible itself says I'mpossible

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    168

    Re: How to know which running process is a system process

    No I want to use these in vb
    Regards,

    Piyush


    Nothing is Impossible because the word impossible itself says I'mpossible

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

    Re: How to know which running process is a system process

    Quote Originally Posted by pbuddy_8
    No I want to use these in vb
    I found this. I ran, and really don't know what it is telling me, but I'm sure you will.
    VB Code:
    1. Private Declare Function GetCurrentProcess Lib "Kernel32.dll" () As Long
    2. Private Declare Function GetProcessAffinityMask Lib "Kernel32.dll" ( _
    3.     ByVal hProcess As Long, ByRef lpProcessAffinityMask As Long, _
    4.     ByRef SystemAffinityMask As Long) As Long
    5.  
    6.  
    7. Private Sub Form_Load()
    8.     Dim ProcMask As Long, SysMask As Long
    9.  
    10.  
    11.     Call GetProcessAffinityMask(GetCurrentProcess(), ProcMask, SysMask)
    12.  
    13.  
    14.     Debug.Print "Process affinity mask: 0x" & Hex(ProcMask)
    15.     Debug.Print "SystemAffinityMask: 0x" & Hex(SysMask)
    16. End Sub

  11. #11
    New Member
    Join Date
    Apr 2007
    Posts
    1

    Re: How to know which running process is a system process

    Here is what I came up with.

    The data returned from the GetProcessAffinityMask contains what processors are available and which are currently in the mask, just because more than one processor is in the mask does not mean it will be used.

    The data it bit-packed into the return variables, each bit is a processor.

    7 6 5 4 3 2 1 0 Processor #
    0 0 0 0 0 0 1 1 Processors Available

    If you have 2 processor your SystemMask value would probably be 3 (00000011) in bianary

    The code presented will find the last processor and set the process to only use last processor. If you only have 1 processor nothing will be done.

    Knowing this information the code should be self explanitory

    Your little bit of code above helped me so I thought I would share this.

    Thanks,

    William Solberg



    Code:
    Private Declare Function GetCurrentProcess Lib "Kernel32.dll" () As Long
    Private Declare Function GetProcessAffinityMask Lib "Kernel32.dll" ( _
    ByVal hProcess As Long, ByRef lpProcessAffinityMask As Long, _
    ByRef SystemAffinityMask As Long) As Boolean
    Private Declare Function SetProcessAffinityMask Lib "Kernel32.dll" ( _
    ByVal hProcess As Long, ByVal dwProcessAffinityMask As Long) As Long
    
    Private Sub Form_Load()
        Dim ProcMask As Long, SysMask As Long
        
        If GetProcessAffinityMask(GetCurrentProcess(), ProcMask, SysMask) Then
            If SysMask > 1 Then
                Dim processor As Integer
                processor = 0
                For i = 1 To 7 'Looks for other processor besides 0
                    If checkbit(SysMask, i) Then processor = i
                Next i
                If processor Then
                    Dim ProcessorMask As Long
                    ProcessorMask = 2 ^ processor 'Creates the mask for only the last processor found
                    If SetProcessAffinityMask(GetCurrentProcess(), ProcessorMask) Then
                        ' Any special code you want to perform if successful
                    End If
                End If
            End If
        End If
    End Sub
    
    Private Function checkbit(ByVal n As Integer, bitnumber as Integer) As Boolean
        Dim i As Integer
        For i = 0 To 7
            If 2 ^ i And n Then
                If bitnumber = i Then
                    checkbit = True
                    Exit Function
                End If
            End If
        Next i
    End Function
    Last edited by WilliamSolberg; Apr 26th, 2007 at 11:26 AM.

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