|
-
Oct 11th, 2005, 04:41 AM
#1
Thread Starter
Addicted Member
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
-
Oct 11th, 2005, 04:43 AM
#2
Thread Starter
Addicted Member
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
-
Oct 11th, 2005, 05:52 AM
#3
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.
-
Oct 11th, 2005, 05:55 AM
#4
Thread Starter
Addicted Member
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
-
Oct 11th, 2005, 06:00 AM
#5
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.
-
Oct 11th, 2005, 07:17 AM
#6
Thread Starter
Addicted Member
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
-
Oct 11th, 2005, 07:40 AM
#7
Re: How to know which running process is a system process
 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?
-
Oct 11th, 2005, 07:49 AM
#8
Thread Starter
Addicted Member
Re: How to know which running process is a system process
Regards,
Piyush
Nothing is Impossible because the word impossible itself says I'mpossible
-
Oct 11th, 2005, 07:50 AM
#9
Thread Starter
Addicted Member
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
-
Oct 11th, 2005, 07:58 AM
#10
Re: How to know which running process is a system process
 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:
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 Long
Private Sub Form_Load()
Dim ProcMask As Long, SysMask As Long
Call GetProcessAffinityMask(GetCurrentProcess(), ProcMask, SysMask)
Debug.Print "Process affinity mask: 0x" & Hex(ProcMask)
Debug.Print "SystemAffinityMask: 0x" & Hex(SysMask)
End Sub
-
Apr 26th, 2007, 10:20 AM
#11
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|