如何记录一台机子开机的时间和关机的时间,,,
请给出原码谢谢!!!!!

解决方案 »

  1.   

    如何用VB制作一个开机关机记录程序。
      首先了解这个程序的工作原理:在计算机启动后,Windows打开这个程序,程序便会自动记录下开机的时间,当关机时,Windows关闭这个程序,程序会记录下关机的时间,并把它们以.txt格式保存下来。
      接着,开始制作程序和设置系统。
      第一步:打开VB,新建一个窗体,用鼠标左键双击窗体,输入以下代码。
      Dim begintime
      Private Sub Form_Load()
      Me.Hide
      begintime=Now
      End Sub
      Private Sub Form_Unload(Cancel As Integer)
      endtime=Now
      n=DateDiff(″N″,begintime,endtime)
      Dim fso As New FileSystemObject
      Dim txtfile As TextStream
      Set a=App
      If fso.FileExists(a.Path & ″\开机记录.txt″) Then
      Set txtfile=fso.OpenTextFile(a.Path & ″\开机记录.txt″,ForAppending)
      Else
      Set txtfile=fso.OpenTextFile(a.Path & ″\开机记录.txt″,ForWriting,True)
      End If
      txtfile.Write ″开机时间″ & begintime
      txtfile.Write ″  ″&″关机时间″& endtime
      txtfile.Write ″  ″&″时间长度″& n & ″分钟″
      txtfile.WriteBlankLines 2
      End Sub
      第二步:单击“文件”菜单中的“生成工程.EXE”选项(或 “File” 菜单中的“Make *.EXE”选项),选择路径保存。
      第三步:在Windows资源管理器中将刚制作的程序复制到计划任务中,并双击它。在“计划”选项卡中将程序设置为每次启动计算机时运行。重新启动计算机。
      最后,讲一下如何查看开机记录。当再次开机时,便可以在保存程序的文件夹中看到一个名为“开机记录”的TXT文件,打开它,就可以看到上次开机的记录。
      

  2.   

    如何自动记录计算机开机时间?Option Explicit
    Private Sub Command1_Click()
    Dim TimeCalc As Date
       TimeCalc = Timer
       Label1.Caption = "希望本计算机让您使用愉快"   Do While Timer - TimeCalc < 1
         DoEvents
       Loop   Unload Me
    End SubPrivate Sub Form_Load()
    Dim Today As Date
    Dim DayString As String
    Dim PathString As String
    Dim DateRec As Integer
       Today = Now   PathString = App.Path
       If Right(PathString, 1) <> "\" Then
         PathString = PathString + "\"
       End If
       If Dir(PathString + "StartPc.log") <> "" Then
         DateRec = FreeFile
         Open PathString + "StartPc.log" For Input As #DateRec
         Line Input #DateRec, DayString
         Close #DateRec     Label1.Caption = "你上次开机是[" & DayString & "]"
       Else
         Label1.Caption = "你第一次使用本计算机"
       End If   DateRec = FreeFile
       Open PathString + "StartPc.log" For Output As #DateRec   DayString = Today
       Print #DateRec, DayString   Close #DateRec
    End Sub上述程序略加修改并放入启动中即可实现对系统开机的记录。
      

  3.   

    用now()函数得到当前时间,在程序启动和关闭时记录时间。把程序放进启动
      

  4.   

    Private Declare Function GetTickCount Lib "kernel32" () As LongPrivate Sub Timer1_Timer()
    '系统工作时间
    Call GetTickCount
      h = Int(GetTickCount / 1000 / 3600)
      m = Int((GetTickCount / 1000 / 3600 - h) * 60)
      Label1.Caption = "系统已经工作" & h & "小时" & m & "分钟"
      
    End Sub
    得到系统工作时间的代码。对于开机时间可以根据当前时间-运行时间就得出
    关机时间则需要自己写文件,但是觉得不是很方便的
      

  5.   

    Option ExplicitPrivate Declare Function GetTickCount Lib "kernel32" () As LongPrivate Sub Form_Load()
        Form1.BackColor = &HFF0000
        Label1.AutoSize = True
        Label1.BackColor = &HFF0000
        Label1.ForeColor = &H80FF80
        Label2.AutoSize = True
        Label2.BackColor = &HFF0000
        Label2.ForeColor = &H80FF80
        Form1.BorderStyle = 0
    End SubPrivate Sub Label1_DblClick()
        End
    End SubPrivate Sub Timer1_Timer()
        Call GetTickCount
        Dim h, m, s
        h = Int(GetTickCount / 1000 / 3600)
        m = Int((GetTickCount / 1000 / 3600 - h) * 60)
        s = Int((((GetTickCount / 1000 / 3600 - h) * 60) - m) * 60)
        Label1.Caption = "系统已工作:" & h & "小时" & m & "分钟" & s & "秒"
        Label2.Caption = "     您现在应该让系统休息了,请在30秒内保存并且关机,否则后果自负!"
    '    Dim closeTime, nowTime
    '    closeTime = #12:01:00 PM#
    '    nowTime = Format("h:m:s")
    '    If nowTime >= closeTime Then
    '    Label2.Visible = True
    '    End If
    End Sub
      

  6.   

    在nt内核的系统中可以查看系统日志// 管理工具---事件查看器---系统日志//信息来源为:eventlog