开发者

How to get the idle time in Windows XP using VBA?

I would like to know the current idle time from user input on a given Windows XP machine programmatically. I am using VBA in MS Access. What opti开发者_如何学JAVAons do I have?


I used the following to obtain the solution.

Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function GetLastInputInfo Lib "user32" (plii As Any) As Long

Private Type LastInputInformation

    cbSize As Long

    dwTime As Long

End Type

Public Function GetUsersIdleTime() As Long

    Dim lii As LastInputInformation

    lii.cbSize = Len(lii)

    Call GetLastInputInfo(lii)

    GetUsersIdleTime = FormatNumber((GetTickCount() - lii.dwTime) / 1000, 2)

End Function

There are other parts of the system which can be idle such as,

  • CPU
  • Disk
  • Network
  • Other devices

To find out more regarding performance and other idle types see this SO post here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜