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