分享

No3:luacom WMI monitor process create and close

 quasiceo 2014-01-03
2012-03-06 20:16 144人阅读 评论(0) 收藏 举报

luacom中使用WMI监视进行的创建和关闭。还是挺酷的。然后打开一个Notepad.exe,再关闭它,就能看到两行输出。

WMI入门

  1. package.cpath=[[C:\Program Files\Lua\5.1\clibs\?.dll]]  
  2. require "luacom"  
  3.   
  4. strComputer = "mycomputername"  
  5. objWMIService = luacom.GetObject("winmgmts:{impersonationLevel=Impersonate}!\\\\"..strComputer.."\\root\\cimv2")  
  6.   
  7. cSink = luacom.CreateObject( "WbemScripting.SWbemSink")  
  8. dSink = luacom.CreateObject( "WbemScripting.SWbemSink")  
  9.   
  10. cSinkh = {}  
  11. function cSinkh:OnObjectReady(objObject, objAsyncContext)  
  12. print ("Process Create Detected: ",objObject:TargetInstance ():Name())  
  13. end  
  14. function cSinkh:OnCompleted(objObject, objAsyncContext)  
  15. print ("Completed")  
  16. end  
  17.   
  18. dSinkh = {}  
  19. function dSinkh:OnObjectReady(objObject, objAsyncContext)  
  20. print ("Process Delete Detected: ",objObject:TargetInstance ():Name())  
  21. end  
  22. function dSinkh:OnCompleted(objObject, objAsyncContext)  
  23. print ("Completed")  
  24. end  
  25.   
  26.   
  27. objWMIService:ExecNotificationQueryAsync( dSink, "SELECT * FROM __InstanceDeletionEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'")  
  28. objWMIService:ExecNotificationQueryAsync (cSink, "SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'")  
  29.   
  30. luacom.Connect (cSink,cSinkh)  
  31. luacom.Connect (dSink,dSinkh)  
  32.   
  33. luacom.StartMessageLoop()  



更多 0

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多