From: Tom Lavedas on
On Jan 7, 3:42 pm, "bob123" <bob...(a)gmail.com> wrote:
> OK thanks
> but this is for citrix server
> and maybe it can have more than one
> notepad.exe (for example)
> I need to kill only my notepad.exe
> Is it possible to list only my processes ?
> Thanks again

That can't be done directly. It is necessary to check each process'
owner, something like this ...

sTheProcess = "BLABLA.EXE"
sUser = "yourusername"
strComputer = "." ' means this computer

Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

for each Process in oWMI.InstancesOf("Win32_Process")
if (UCASE(Process.Name) = sTheProcess) then
set oOutParams = oWMI.ExecMethod("Win32_Process.Handle='" _
& Process.Handle & "'", "GetOwner")
if lcase(oOutParams.User) = sUser then Process.Terminate
End If
next
_____________________
Tom Lavedas
From: ekrengel on
On Jan 7, 4:57 pm, Tom Lavedas <tlave...(a)gmail.com> wrote:
> On Jan 7, 3:42 pm, "bob123" <bob...(a)gmail.com> wrote:
>
> > OK thanks
> > but this is for citrix server
> > and maybe it can have more than one
> > notepad.exe (for example)
> > I need to kill only my notepad.exe
> > Is it possible to list only my processes ?
> > Thanks again
>
> That can't be done directly.  It is necessary to check each process'
> owner, something like this ...
>
> sTheProcess = "BLABLA.EXE"
> sUser = "yourusername"
> strComputer = "."  ' means this computer
>
>    Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
>
>    for each Process in oWMI.InstancesOf("Win32_Process")
>        if (UCASE(Process.Name) = sTheProcess)  then
>          set oOutParams = oWMI.ExecMethod("Win32_Process.Handle='" _
>                                   & Process.Handle & "'", "GetOwner")
>          if lcase(oOutParams.User) = sUser then Process.Terminate
>        End If
>    next
> _____________________
> Tom Lavedas

This works as well, just another way of writing it:

sUser = "username"

With GetObject("winmgmts:root\cimv2")
For Each objProcess in .ExecQuery _
("SELECT commandline FROM Win32_Process" _
& " WHERE Name = 'NOTEPAD.exe'",,48)
With .ExecMethod _
("Win32_Process.Handle='" _
& objProcess.Handle & "'", "GetOwner")
If Lcase(.User) = sUser Then
objProcess.Terminate()
End If
End With
Next
End With

msgbox "done!"
WScript.Quit
From: bob123 on
OK thanks Erick
you "win the award"

"ekrengel" <erickrengel5(a)gmail.com> a �crit dans le message de news:
ac1c3236-3362-43af-95c0-929b7ed7fd0a(a)f6g2000vbp.googlegroups.com...
On Jan 7, 4:57 pm, Tom Lavedas <tlave...(a)gmail.com> wrote:
> On Jan 7, 3:42 pm, "bob123" <bob...(a)gmail.com> wrote:
>
> > OK thanks
> > but this is for citrix server
> > and maybe it can have more than one
> > notepad.exe (for example)
> > I need to kill only my notepad.exe
> > Is it possible to list only my processes ?
> > Thanks again
>
> That can't be done directly. It is necessary to check each process'
> owner, something like this ...
>
> sTheProcess = "BLABLA.EXE"
> sUser = "yourusername"
> strComputer = "." ' means this computer
>
> Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
>
> for each Process in oWMI.InstancesOf("Win32_Process")
> if (UCASE(Process.Name) = sTheProcess) then
> set oOutParams = oWMI.ExecMethod("Win32_Process.Handle='" _
> & Process.Handle & "'", "GetOwner")
> if lcase(oOutParams.User) = sUser then Process.Terminate
> End If
> next
> _____________________
> Tom Lavedas

This works as well, just another way of writing it:

sUser = "username"

With GetObject("winmgmts:root\cimv2")
For Each objProcess in .ExecQuery _
("SELECT commandline FROM Win32_Process" _
& " WHERE Name = 'NOTEPAD.exe'",,48)
With .ExecMethod _
("Win32_Process.Handle='" _
& objProcess.Handle & "'", "GetOwner")
If Lcase(.User) = sUser Then
objProcess.Terminate()
End If
End With
Next
End With

msgbox "done!"
WScript.Quit


From: bob123 on

Maybe too much,
is it possible to get the current user ?
Thank you very much
>>
>> That can't be done directly. It is necessary to check each process'
>> owner, something like this ...
>>
>> sTheProcess = "BLABLA.EXE"
>> sUser = "yourusername"
>> strComputer = "." ' means this computer
>>
>> Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
>>
>> for each Process in oWMI.InstancesOf("Win32_Process")
>> if (UCASE(Process.Name) = sTheProcess) then
>> set oOutParams = oWMI.ExecMethod("Win32_Process.Handle='" _
>> & Process.Handle & "'", "GetOwner")
>> if lcase(oOutParams.User) = sUser then Process.Terminate
>> End If
>> next
>> _____________________
>> Tom Lavedas
>
> This works as well, just another way of writing it:
>
> sUser = "username"
>
> With GetObject("winmgmts:root\cimv2")
> For Each objProcess in .ExecQuery _
> ("SELECT commandline FROM Win32_Process" _
> & " WHERE Name = 'NOTEPAD.exe'",,48)
> With .ExecMethod _
> ("Win32_Process.Handle='" _
> & objProcess.Handle & "'", "GetOwner")
> If Lcase(.User) = sUser Then
> objProcess.Terminate()
> End If
> End With
> Next
> End With
>
> msgbox "done!"
> WScript.Quit
>


From: Reventlov on
Il giorno Sat, 9 Jan 2010 07:36:34 +0100, "bob123" <bob123(a)gmail.com> ha scritto:

>
>Maybe too much,
>is it possible to get the current user ?
>Thank you very much
>>>
' CurrentUserID()
' UserFullName(UserID)


Function CurrentUserID()
CurrentUserID=
CreateObject("WScript.Shell").ExpandEnvironmentStrings("%USERNAME%")
End Function

Function UserFullName(UserID)
Dim StrDomain, objDomain, objUser
' Ottiene il nome del dominio e dell'utente
strDomain = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%USERDOMAIN%")
MsgBox StrDomain
MsgBox UserID
' Si collega al server e richiede l'utente
Set objDomain = GetObject("WinNT://" & strDomain)
Set objUser = objDomain.GetObject("user", UserID)
UserFullName=objUser.Fullname
'objUser.Name
'objUser.FullName
'objUser.Description
'objUser.LastLogin
End Function


--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--