Utilties similar to GetTasks

Utilties similar to GetTasks

Postby nageswaragunupudi » Wed Jan 30, 2008 4:57 am

Here are some utilties to get the processes running, kill a process, get users who are running an exe, for any one who may be inerested. Limitations are that these utilties are based on WMI services and work only with xHarbour. I do not know how to make them work with Harbour.

Code: Select all  Expand view  RUN
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
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby Antonio Linares » Wed Jan 30, 2008 9:52 am

Thanks! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Rick Lipkin » Wed Jan 30, 2008 1:29 pm

nageswaragunupudi

Question .. the GetExeUsers() function .. I am looking for a program that will tell me 'whohas' what executable runing on a Windows 200(x) server.. looking for users who may have a program running.

Example .. navigate to the server folder where the executable is located and ( launch a program ) to tell me who has it open ??

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Postby nageswaragunupudi » Wed Jan 30, 2008 5:26 pm

Mr Rick Liptin

First as to the above function, this is working on 2003 servers. When executed by user having administrative privileges, this function lists all users using the exe. Here is the improved version.

Code: Select all  Expand view  RUN
FUNCTION GetExeUsers( cExe )

   local oWmi, oList, oProc
   local cUser, cDomain
   local aList := {}

   oWmi     := WmiService()
   oList    := oWmi:ExecQuery( "select * from Win32_Process where Name = '" + cExe + "'" )
   for each oProc in oList
      if ( oProc:GetOwner( @cUser, @cDomain ) ) == 0
         cUser = cDomain + "\" + cUser
         if AScan( aList, cUser ) == 0
            AAdd( aList, cUser )
         endif
      endif
   next

return aList


If we ourselves ( with administrative privileges) login to the server , there are many easier ways.

1) This is the simple thing I do. Open TaskManager, check "Show Processes from All Users" check box, sort the list on Image name in Processes tab and look for the executable name. We can see names of all users executing that program.

2) Run Adminstrative Toops -> Computer Management. Go to Shared Folders -> Open Files. You see all open executables/dlls and users who are using them.

I am not sure if I answered you what you are looking for.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby Rick Lipkin » Thu Jan 31, 2008 12:02 am

NageswaraRao

I got your vbs script in my private mail .. I will try it in the morning .. and let you know

Rick
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 44 guests