c++ - 当程序在 Windows 中使用 C++ 运行时,如何监听/识别?

标签 c++ windows events listen

具体来说,我想听听程序何时运行并记录信息,例如:时间戳、可执行文件、窗口名称和用户。

最佳答案

或者,使用 WMI 界面找出正在运行的程序并采取适当的操作。在下面的 VBScript 代码中,正在使用 Select * from Win32_Process 查询 WMI 子系统,以更改进程优先级。找出 Win32_Process 可用的其他属性,您应该找到朝着您想要的方向前进的东西。

Const NORMAL_PRIORITY = 32
Const LOW_PRIORITY = 64
Const REALTIME_PRIORITY = 128
Const HIGH_PRIORITY = 256
Const BELOWNORMAL_PRIORITY = 16384
Const ABOVENORMAL_PRIORITY = 32768

Function SetPriority( sProcess, nPriority )
    Dim sComputer
    Dim oWMIService
    Dim cProcesses
    Dim oProcess
    Dim bDone

    bDone = False
    sComputer = "."
    Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")

    Set cProcesses = oWMIService.ExecQuery ("Select * from Win32_Process Where Name = '" & sProcess & "'")
    For Each oProcess in cProcesses
        oProcess.SetPriority( nPriority )
        bDone = True        
    Next
    SetPriority = bDone
End Function

关于c++ - 当程序在 Windows 中使用 C++ 运行时,如何监听/识别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/186004/

相关文章:

java - 封装与数据隐藏?

windows - 访问远程服务器以执行计算任务的最简单方法

windows - 防止跨进程 SendMessage 调用

c - 在 Quake 中使用 CreateEvent()

c++ - 使用 CreateWindow(Ex) 创建虚拟父控件(如面板)

c++ - 对非常量的引用的初始值必须是左值,通过引用错误传递对象类型

c++ - 复制构造函数和动态分配

c++ - Qt 不发射信号

javascript - 如何在动态生成的元素上触发事件(在mootools中)

JavaScript 查找元素之间