Mombu the Microsoft Forum sponsored links

Go Back   Mombu the Microsoft Forum > Microsoft > Terminating Process in Terminal Server Environment
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 21st April 00:05
matthias jarling
External User
 
Posts: 1
Default Terminating Process in Terminal Server Environment



Hi,

The following code to end processes works fine, but terminates the processes
of *all* logged on users (if the code is executed by an admin account). I
just want to kill the current users task.

--
Public Function funQuitProcesses(ByVal strProcessName As String) As Boolean
If Len(strProcessName) > 0 Then
Dim objWMI As Object
Set objWMI = GetObject("winmgmts:")

Dim strWMISQL As String
strWMISQL = "SELECT * FROM win32_process WHERE name = '" &
strProcessName & "'"

Dim objProcesses As Object
Set objProcesses = objWMI.ExecQuery(strWMISQL)

Dim objProcess As Object

For Each objProcess In objProcesses
objProcess.Terminate
Next

Set objProcesses = Nothing
Set objWMI = Nothing

funQuitProcesses = True
Else
funQuitProcesses = False
End If
End Function
--

What's the correct where-clause for this? Should be something like 'where
sessionid = " & TheUsersCurrentSessionID ' or 'where "processowner = " &
CurrentUser()'

thanks in advance, MJ
  Reply With Quote


  sponsored links


2 21st April 00:06
torgeir bakken \(mvp\)
External User
 
Posts: 1
Default Terminating Process in Terminal Server Environment



Hi,

objProcess.GetOwner should do the job, something like this (strUser
would be an input parameter to the function):

For Each objProcess In objProcesses

lngRet = objProcess.GetOwner(strProcUser, strProcDomain)
If lngRet = 0 Then
If LCase(strProcUser) = LCase(strUser) Then
objProcess.Terminate
End If
End If

Next

--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666