記載Windows使用的時間
有時候你需要記下每次Windows開啟和關閉的時間,下面這個小程序就可以完成這個功能,你可以把它放在Windows開始菜單的“啟動”文件夾裡面,這樣當你進入Windows時,這個小程序就會自動啟動(不可見),並在你指定的文件中寫下當時的時間,在你推出Windows系統時,小程序會關閉並記下離開的時間,並關閉記錄文件。
Private Sub Form_Load()
Left = -10000
Top = -10000
Open "c:\aPPS\log.txt" For Append As #1
Print #1, "On: " & CStr(Now)
Close #1
End Sub
Private Sub Form_Unload(Cancel As Integer)
Open "c:\aPPS\log.txt" For Append As #1
Print #1, "Off:" & CStr(Now)
Close #1
End
End Sub
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, "Calculator")
Debug.Print winHwnd
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
If RetVal = 0 Then
MsgBox "置入消息錯誤!"
End If
Else
MsgBox "Calculator沒有打開!"
End If
Declare Function FindWindow Lib "user32" Alias _"FindWindowA" (ByVal lpClassName As String, _ByVal lpWindowName As String) As Long
Declare Function PostMessage Lib "user32" Alias _"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10
If App.PrevInstance = True Then
Call MsgBox("這個程序正在運行!",_vbExclamation)
End
End If
Declare Sub Sleep Lib "kernel32" _(ByVal dwMilliseconds As Long)
'延遲1秒
Call Sleep(1000)
Declare Function SetDoubleClickTime _Lib "user32" Alias "SetDoubleClickTime" _(ByVal wCount As Long) As Long