Code: Select all
FUNCTION GetProcesses()
local oWmi, oList, oProc
local cUser, cDomain
local aList := {}
oWmi := WmiService()
oList := oWmi:ExecQuery( "select * from Win32_Process" )
for each oProc in oList
if ( oProc:GetOwner( @cDomain, @cUser ) ) == 0
// Windows Documentation says the parameters are user, domain
// but I am getting the params in reverse order
// domain, user
AAdd( aList, { oProc:Caption, oProc:Name, cUser, cDomain } )
endif
next
return aList
FUNCTION KillProcess( cExe )
local oWmi, oList, oProc
oWmi := WmiService()
oList := oWmi:ExecQuery( "select * from Win32_Process where Name = '" + cExe + "'" )
for each oProc in oList
oProc:Terminate()
next
return nil
FUNCTION GetExeUsers( cExe )
local oWmi, oList, oProc
local cUser, cDomain
local aList := {}
cExe := upper( alltrim( cExe ) )
oWmi := WmiService()
oList := oWmi:ExecQuery( "select * from Win32_Process" )
for each oProc in oList
if cExe == upper( oProc:Caption )
if ( oProc:GetOwner( @cDomain, @cUser ) ) == 0
if AScan( aList, cUser ) == 0
AAdd( aList, cUser )
endif
endif
endif
next
return aList
FUNCTION WMIService()
// It would be useful to keep this function in the library
static oWMI
local oLocator
if oWMI == nil
oLocator := CREATEOBJECT( "wbemScripting.SwbemLocator" )
oWMI := oLocator:ConnectServer()
endif
return oWMI