VB怎么做得到上次电脑关闭的时间?
RT
追问:不用添加按钮吗 只要开着?运行的时候这里有问题。。FileCopy StrExeFile, StrSysPath & "\gong.exe"
RT
追问:不用添加按钮吗 只要开着?运行的时候这里有问题。。FileCopy StrExeFile, StrSysPath & "\gong.exe"
答案:'以前写过一个小软件,自己修改一下,可以记录开关机时间Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Dim StrExeFile As String
Dim StrSysPath As String
Dim RecFileName As String
Dim RecTemp As String
Private Sub Form_Load()
If App.PrevInstance Then End
Dim WshShell As Object
Set WshShell = CreateObject("wscript.shell")'获得系统路径
StrSysPath = Space(256)
GetSystemDirectory StrSysPath, 256
StrSysPath = Trim(StrSysPath)
StrSysPath = Left(StrSysPath, Len(StrSysPath) - 1)'获得文件所在路径
WindowState = vbMinimized
Hide
If Dir(StrSysPath & "\gong.exe") = "" ThenStrExeFile = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\") & App.EXEName & ".exe"
FileCopy StrExeFile, StrSysPath & "\gong.exe"
End If
WshShell.regwrite "HKLM\software\microsoft\windows\currentversion\run\gong.exe", StrSysPath & "\gong.exe"
RecFileName = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\") & "gong.txt"
If Dir(IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\") & "gong.txt") <> "" Then
Open RecFileName For Input As #1
RecTemp = StrConv(InputB(LOF(1), 1), vbUnicode) '读入源文件
Close #1
End If
RecTemp = RecTemp & "开机时间:" & Date & Space(4) & Time & Chr(13) & Chr(10)WriteFile
End SubFunction WriteFile()
Open RecFileName For Output As #1
Print #1, RecTemp
Close #1
End FunctionPrivate Sub Form_Unload(Cancel As Integer)
RecTemp = RecTemp & "关机时间:" & Date & Space(4) & Time & Chr(13) & Chr(10)
WriteFile
End SubGetTickCount函数 记录系统启动到调取时的时间 单位毫秒 可以先记录系统当前时间 然后减去GetTickCount函数返回值 但是只能记录系统开启时间 不能记录机器启动时间
然后在程序卸载事件里写记录当前系统时间 然后保存至文件 下次登录时显示就行了
上一个:VB怎样实现最小化托盘,怎样实现悬浮框?
下一个:VB涓皟鐢ˋPI鍑芥暟閮芥湁浠€涔堟妧宸э紵 - 宸茶В鍐?- 鎼滄悳闂棶