List Windows processes or servicesTag(s): WinAPI/Registry


Something similar to the Task List.
OleObject mssc
int li_rc
string ls_code
Any res

mssc = CREATE OleObject
li_rc = mssc.ConnectToNewObject( "MSScriptControl.ScriptControl" )
mssc.language = "VBScript"

ls_code = "function services() ~r~n" + &
          "strComputer=~".~"~r~n" + &
          "Set objWMIService = GetObject(~"winmgmts:~"" + &
          "& ~"{impersonationLevel=impersonate}!\\~"" +&
          " & strComputer & ~"\root\cimv2~")~r~n" + &
          "Set colProcesses = objWMIService.ExecQuery(" + &
          "~"select * from win32_process~" )~r~n" + &
            "s = ~"~"~r~n" + &
          "For Each objProcess In colProcesses~r~n" + &
           " s = s & objProcess.Name & vbCr~r~n" + & 
           "Next~r~n" + &
              "services = s~r~n" + &
              "end function"
mssc.AddCode(ls_code)             
res = mssc.Eval("services()")
MessageBox("",String(res))

mssc.DisconnectObject()
DESTROY mssc
You can get the list of the running services by replacing "select * from win32_process" by "select * from win32_service"

Useful links
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_process.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_service.asp


blog comments powered by Disqus