473,624 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 = "ProcessNam e"

Dim myProcesses() As Process

Dim myProcess As Process

myProcesses = Process.GetProc essesByName(myP rocessName)

For Each myProcess In myProcesses

Try

myProcess.Kill( )

Catch ex As Exception

MsgBox(ex.ToStr ing)

End Try

Next
May 16 '07 #1
4 3294
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 = "ProcessNam e"

Dim myProcesses() As Process

Dim myProcess As Process

myProcesses = Process.GetProc essesByName(myP rocessName)

For Each myProcess In myProcesses

Try

myProcess.Kill( )

Catch ex As Exception

MsgBox(ex.ToStr ing)

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 ProcessIdToSess ionId _
Lib "kernel32" (ByVal dwProcessId As Long, _
ByRef pSessionId As Long) As Long

Private Declare Function GetCurrentProce ssId Lib "kernel32" () As Long
Private Declare Function GetSystemMetric s _
Lib "user32" (ByVal nIndex As Long) As Long


Private Function GetTSSessionID( ) As Long

Dim lngSessionID As Long
Dim lngReturnCode As Long

If GetSystemMetric s(SmREMOTESESSI ON) <0 Then
'It's terminal services

lngReturnCode = ProcessIdToSess ionId(GetCurren tProcessId(), 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.ne tschreef in bericht
news:2c******** *************** ***@news.east.c ox.net...
>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 = "ProcessNam e"

Dim myProcesses() As Process

Dim myProcess As Process

myProcesses = Process.GetProc essesByName(myP rocessName)

For Each myProcess In myProcesses

Try

myProcess.Kill ()

Catch ex As Exception

MsgBox(ex.ToSt ring)

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 ProcessIdToSess ionId _
Lib "kernel32" (ByVal dwProcessId As Long, _
ByRef pSessionId As Long) As Long

Private Declare Function GetCurrentProce ssId Lib "kernel32" () As Long
Private Declare Function GetSystemMetric s _
Lib "user32" (ByVal nIndex As Long) As Long


Private Function GetTSSessionID( ) As Long

Dim lngSessionID As Long
Dim lngReturnCode As Long

If GetSystemMetric s(SmREMOTESESSI ON) <0 Then
'It's terminal services

lngReturnCode = ProcessIdToSess ionId(GetCurren tProcessId(),
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.c omwrote in message
news:e1******** *****@TK2MSFTNG P03.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.ne tschreef in bericht
news:2c******** *************** ***@news.east.c ox.net...
>>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 = "ProcessNam e"

Dim myProcesses() As Process

Dim myProcess As Process

myProcesses = Process.GetProc essesByName(myP rocessName)

For Each myProcess In myProcesses

Try

myProcess.Kil l()

Catch ex As Exception

MsgBox(ex.ToS tring)

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 ProcessIdToSess ionId _
Lib "kernel32" (ByVal dwProcessId As Long, _
ByRef pSessionId As Long) As Long

Private Declare Function GetCurrentProce ssId Lib "kernel32" () As Long
Private Declare Function GetSystemMetric s _
Lib "user32" (ByVal nIndex As Long) As Long


Private Function GetTSSessionID( ) As Long

Dim lngSessionID As Long
Dim lngReturnCode As Long

If GetSystemMetric s(SmREMOTESESSI ON) <0 Then
'It's terminal services

lngReturnCode = ProcessIdToSess ionId(GetCurren tProcessId(),
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.coms chreef in bericht
news:%2******** ********@TK2MSF TNGP02.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.c omwrote in message
news:e1******** *****@TK2MSFTNG P03.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.ne tschreef in bericht
news:2c******* *************** ****@news.east. cox.net...
>>>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
environmen t so
that only user's own processes to be eliminated?
Thanks

Bill

Dim myProcessName As String = "ProcessNam e"

Dim myProcesses() As Process

Dim myProcess As Process

myProcesse s = Process.GetProc essesByName(myP rocessName)

For Each myProcess In myProcesses

Try

myProcess.Ki ll()

Catch ex As Exception

MsgBox(ex.To String)

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 ProcessIdToSess ionId _
Lib "kernel32" (ByVal dwProcessId As Long, _
ByRef pSessionId As Long) As Long

Private Declare Function GetCurrentProce ssId Lib "kernel32" () As Long
Private Declare Function GetSystemMetric s _
Lib "user32" (ByVal nIndex As Long) As Long


Private Function GetTSSessionID( ) As Long

Dim lngSessionID As Long
Dim lngReturnCode As Long

If GetSystemMetric s(SmREMOTESESSI ON) <0 Then
'It's terminal services

lngReturnCode = ProcessIdToSess ionId(GetCurren tProcessId(),
lngSessionI D)

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
7806
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 in this array and the number of times it has been duplicated. can someone help?
2
3859
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 are thinking of putting the hottest tables on a solid state (RAM) drive for improved performance. Problem is: which are the hottest tables? Would like to do this based on hard data instead of developer/vendor guesses. Any suggestions are much...
0
1000
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 looking at the code, what's gone wrong - but if the VS.Net program can show, or give an indication of resources which are either building up (as this reader reads/processes), it would help a lot. Thanks for any help,
1
1559
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
23067
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 to a pool. If I assign only one application to a applicaton pool and have multiple worker processes assigned to that pool. Will my application be processed by many worker processes?
6
2488
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 locked, I want a messagebox to tell that the user has to close the file first. Is there a way to identify an exception by some kind of unique number or something like this? I don't want to identify it on the Exception Message because some users are...
1
1557
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
2127
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 EXACTLY ONE process is running. Anyway, other "Update.exe" processes may run simultaneously at one time, so I need to check the right one. What's the most reliable method? Thanks.
1
1738
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 get this information from System.GetProcesses. Can anyone tell me how to do this? Thanks
0
8680
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8625
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7168
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.