473,390 Members | 1,207 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

How to identify your own processes

I ran into this problem in a Terminal Server environment

When trying to kill all processes having the same name (to avoid hanging
instances of this process), my users ran into permission problem (access
denied) because the routine tried to kill other users' process as well.
Is there away to idenfity process owner in a Terminal server environment so
that only user's own processes to be eliminated?

Thanks

Bill
Dim myProcessName As String = "ProcessName"

Dim myProcesses() As Process

Dim myProcess As Process

myProcesses = Process.GetProcessesByName(myProcessName)

For Each myProcess In myProcesses

Try

myProcess.Kill()

Catch ex As Exception

MsgBox(ex.ToString)

End Try

Next
May 16 '07 #1
4 3276
I ran into this problem in a Terminal Server environment
>
When trying to kill all processes having the same name (to avoid
hanging
instances of this process), my users ran into permission problem
(access
denied) because the routine tried to kill other users' process as
well.
Is there away to idenfity process owner in a Terminal server
environment so
that only user's own processes to be eliminated?
Thanks

Bill

Dim myProcessName As String = "ProcessName"

Dim myProcesses() As Process

Dim myProcess As Process

myProcesses = Process.GetProcessesByName(myProcessName)

For Each myProcess In myProcesses

Try

myProcess.Kill()

Catch ex As Exception

MsgBox(ex.ToString)

End Try

Next
not sur eif this will help.

Its been a long time, but In VB6, i used to do code below at application
startup:

and when the user clicked Help About, i displayed that session id.

its been a few years sionce i was in that environment, so i have not had
to figure this out in dotnet

Private Const SmREMOTESESSION = &H1000

Private Declare Function ProcessIdToSessionId _
Lib "kernel32" (ByVal dwProcessId As Long, _
ByRef pSessionId As Long) As Long

Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function GetSystemMetrics _
Lib "user32" (ByVal nIndex As Long) As Long


Private Function GetTSSessionID() As Long

Dim lngSessionID As Long
Dim lngReturnCode As Long

If GetSystemMetrics(SmREMOTESESSION) <0 Then
'It's terminal services

lngReturnCode = ProcessIdToSessionId(GetCurrentProcessId(), lngSessionID)

If lngReturnCode <0 Then
'Success!
GetTSSessionID = lngSessionID
Else
'Error
GetTSSessionID = 0
End If

Else
'Not Terminal Services
GetTSSessionID = 0
End If

End Function
May 17 '07 #2
Well you could set a mutex and check the process if it has this mutex

i.ow. the mutex should be user specific ( username ?? )

regards

Michel

"Jay Parzych" <ji*****@cox.netschreef in bericht
news:2c**************************@news.east.cox.ne t...
>I ran into this problem in a Terminal Server environment

When trying to kill all processes having the same name (to avoid
hanging
instances of this process), my users ran into permission problem
(access
denied) because the routine tried to kill other users' process as
well.
Is there away to idenfity process owner in a Terminal server
environment so
that only user's own processes to be eliminated?
Thanks

Bill

Dim myProcessName As String = "ProcessName"

Dim myProcesses() As Process

Dim myProcess As Process

myProcesses = Process.GetProcessesByName(myProcessName)

For Each myProcess In myProcesses

Try

myProcess.Kill()

Catch ex As Exception

MsgBox(ex.ToString)

End Try

Next

not sur eif this will help.

Its been a long time, but In VB6, i used to do code below at application
startup:

and when the user clicked Help About, i displayed that session id.

its been a few years sionce i was in that environment, so i have not had
to figure this out in dotnet

Private Const SmREMOTESESSION = &H1000

Private Declare Function ProcessIdToSessionId _
Lib "kernel32" (ByVal dwProcessId As Long, _
ByRef pSessionId As Long) As Long

Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function GetSystemMetrics _
Lib "user32" (ByVal nIndex As Long) As Long


Private Function GetTSSessionID() As Long

Dim lngSessionID As Long
Dim lngReturnCode As Long

If GetSystemMetrics(SmREMOTESESSION) <0 Then
'It's terminal services

lngReturnCode = ProcessIdToSessionId(GetCurrentProcessId(),
lngSessionID)

If lngReturnCode <0 Then
'Success!
GetTSSessionID = lngSessionID
Else
'Error
GetTSSessionID = 0
End If

Else
'Not Terminal Services
GetTSSessionID = 0
End If

End Function


May 17 '07 #3
Jay;

I'm on VS 2005, and I think they should have a way to identify process
owner. I don't really want to resort to using Win32 API.

Michel;
Can you please elaborate?

Thanks again

Bill

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:e1*************@TK2MSFTNGP03.phx.gbl...
Well you could set a mutex and check the process if it has this mutex

i.ow. the mutex should be user specific ( username ?? )

regards

Michel

"Jay Parzych" <ji*****@cox.netschreef in bericht
news:2c**************************@news.east.cox.ne t...
>>I ran into this problem in a Terminal Server environment

When trying to kill all processes having the same name (to avoid
hanging
instances of this process), my users ran into permission problem
(access
denied) because the routine tried to kill other users' process as
well.
Is there away to idenfity process owner in a Terminal server
environment so
that only user's own processes to be eliminated?
Thanks

Bill

Dim myProcessName As String = "ProcessName"

Dim myProcesses() As Process

Dim myProcess As Process

myProcesses = Process.GetProcessesByName(myProcessName)

For Each myProcess In myProcesses

Try

myProcess.Kill()

Catch ex As Exception

MsgBox(ex.ToString)

End Try

Next

not sur eif this will help.

Its been a long time, but In VB6, i used to do code below at application
startup:

and when the user clicked Help About, i displayed that session id.

its been a few years sionce i was in that environment, so i have not had
to figure this out in dotnet

Private Const SmREMOTESESSION = &H1000

Private Declare Function ProcessIdToSessionId _
Lib "kernel32" (ByVal dwProcessId As Long, _
ByRef pSessionId As Long) As Long

Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function GetSystemMetrics _
Lib "user32" (ByVal nIndex As Long) As Long


Private Function GetTSSessionID() As Long

Dim lngSessionID As Long
Dim lngReturnCode As Long

If GetSystemMetrics(SmREMOTESESSION) <0 Then
'It's terminal services

lngReturnCode = ProcessIdToSessionId(GetCurrentProcessId(),
lngSessionID)

If lngReturnCode <0 Then
'Success!
GetTSSessionID = lngSessionID
Else
'Error
GetTSSessionID = 0
End If

Else
'Not Terminal Services
GetTSSessionID = 0
End If

End Function



May 17 '07 #4

well you could modify this

http://www.freevbcode.com/ShowCode.asp?ID=7654
instead of the guid you should create a string containing progname /
username
this should then be implemented in all progs you want to have the ability
to manipulate through the process lib

Now the application , that needs to kill the process can just check for the
existence of the mutex ( mutex is stored at kernel level )

but i guess there should be an easier way , to detect the user context in
wich the app is runing


"Bill Nguyen" <bi*****************@jaco.comschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
Jay;

I'm on VS 2005, and I think they should have a way to identify process
owner. I don't really want to resort to using Win32 API.

Michel;
Can you please elaborate?

Thanks again

Bill

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:e1*************@TK2MSFTNGP03.phx.gbl...
>Well you could set a mutex and check the process if it has this mutex

i.ow. the mutex should be user specific ( username ?? )

regards

Michel

"Jay Parzych" <ji*****@cox.netschreef in bericht
news:2c**************************@news.east.cox.n et...
>>>I ran into this problem in a Terminal Server environment

When trying to kill all processes having the same name (to avoid
hanging
instances of this process), my users ran into permission problem
(access
denied) because the routine tried to kill other users' process as
well.
Is there away to idenfity process owner in a Terminal server
environment so
that only user's own processes to be eliminated?
Thanks

Bill

Dim myProcessName As String = "ProcessName"

Dim myProcesses() As Process

Dim myProcess As Process

myProcesses = Process.GetProcessesByName(myProcessName)

For Each myProcess In myProcesses

Try

myProcess.Kill()

Catch ex As Exception

MsgBox(ex.ToString)

End Try

Next
not sur eif this will help.

Its been a long time, but In VB6, i used to do code below at application
startup:

and when the user clicked Help About, i displayed that session id.

its been a few years sionce i was in that environment, so i have not had
to figure this out in dotnet

Private Const SmREMOTESESSION = &H1000

Private Declare Function ProcessIdToSessionId _
Lib "kernel32" (ByVal dwProcessId As Long, _
ByRef pSessionId As Long) As Long

Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function GetSystemMetrics _
Lib "user32" (ByVal nIndex As Long) As Long


Private Function GetTSSessionID() As Long

Dim lngSessionID As Long
Dim lngReturnCode As Long

If GetSystemMetrics(SmREMOTESESSION) <0 Then
'It's terminal services

lngReturnCode = ProcessIdToSessionId(GetCurrentProcessId(),
lngSessionID)

If lngReturnCode <0 Then
'Success!
GetTSSessionID = lngSessionID
Else
'Error
GetTSSessionID = 0
End If

Else
'Not Terminal Services
GetTSSessionID = 0
End If

End Function




May 18 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Michelle | last post by:
hi, i have created an array from recordset containing user names eg. (davidp, davidp, evenf, patricka, rebeccah) which i have sorted in alphabetical order, but i need to identify duplicates...
2
by: Jeff Roughgarden | last post by:
Does anyone know how to identify the hottest, most active tables in a database? We have hundreds of users hitting a PeopleSoft database with hundreds of tables. We are I/O bound on our SAN, and...
0
by: Mark | last post by:
Hi - in VS.Net 2003, using asp.net - is it possible to setup through a web app, and view which resources are not being closed/disposed? My aspnet_wp is shooting up to 99%, and I can't see from...
1
by: Christopher Attard | last post by:
Hi, I'm getting a list of running processes on a machine using Process.GetProcesses(). Can I identify programmatically which of these processes is running as a service. 10x in advance. Chris
9
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated...
6
by: Pieter | last post by:
Hi, For some procedures that throws exceptions, I would like to show different messages to the user depending on what type of exception he's getting. For instance this one: when the file is...
1
by: 01423481d | last post by:
Hi all Here is a segment of code used to find out all running processes Imports System.Diagnostics .... Dim myProcesses() As Process Dim myProcess As Process
1
by: nano2k | last post by:
Hi I have an application (let's call it Main.exe) and a helper process (call it Update.exe) that periodically updates Main app. Update.exe needs to reside in memory, but I need to make sure that...
1
by: =?Utf-8?B?RFdhdHNvbkNyeXBLZXk=?= | last post by:
I need to be able to monitor a file and identify which processes have accessed them. Kind of like Windows Filemon does. The FileSystemWatcher doesn't seem to provide this information, and I can't...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.