如何获取XP系统的开机时间?

下面给出两种代码,保存到扩展名为vbs的文件中。具体哪个请根据自己需求决定。

一:根据系统日志,查看开机时间和关机时间,---- 使用弹出对话框的形式

Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colLoggedEvents = WMI.ExecQuery("Select * from Win32_NTLogEvent Where Logfile = 'System' And EventCode = '6005' Or EventCode = '6006'")
For Each objEvent In colLoggedEvents
Flag = Flag +1
If Flag = 1 Then
Wscript.Echo "本次开机时间: " & UTCtoNow(objEvent.TimeWritten)
Else
If (flag < 4) Then
If (flag Mod 2) = 0 Then
G = "上次关机时间:" & UTCtoNow(objEvent.TimeWritten) & vbNewLine
Else
K = "上次开机时间:" & UTCtoNow(objEvent.TimeWritten)
Wscript.Echo K & vbNewLine & G
End If
End If
End If
Next 'CreateObject("Wscript.Shell").Run "D:\Document\消费记录.xlsx",3,ture '此处用于测试打开文件 Function UTCtoNow(nD)
If Not IsNull(nD) Then
Set SWDT = CreateObject("WbemScripting.SWbemDateTime")
SWDT.Value = nD
UTCtoNow = SWDT.GetVarDate(True)
End If
End Function

二:下面在给出一个循环查找多次开机记录的方式,并且写到文件并打开  ---- 写文件形式

Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colLoggedEvents = WMI.ExecQuery("Select * from Win32_NTLogEvent Where Logfile = 'System' And EventCode = '6005' Or EventCode = '6006'") filePath="c:\startLog.txt"
set fso=createobject("scripting.filesystemobject")
set file=fso.opentextfile(filePath,2,true)
file.writeline "当前时间:" & Now
file.writeline "最近几次的开机和关机时间:"
file.close
set file=fso.opentextfile("c:\startLog.txt",8,true) Flag = 0
For Each objEvent In colLoggedEvents
Flag = Flag +1
msg = ""
If (flag < 25) Then
If (flag Mod 2) = 0 Then
msg = "关机时间:" & UTCtoNow(objEvent.TimeWritten) & vbNewLine
Else
msg = "开机时间:" & UTCtoNow(objEvent.TimeWritten)
End If
file.writeline msg
End If
Next
file.close
CreateObject("Wscript.Shell").Run filePath,3,ture Function UTCtoNow(nD)
If Not IsNull(nD) Then
Set SWDT = CreateObject("WbemScripting.SWbemDateTime")
SWDT.Value = nD
UTCtoNow = SWDT.GetVarDate(True)
End If
End Function

以下是经过优化代码:保存的文件根据时间生成,提示保存路径,以及增加换行

Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colLoggedEvents = WMI.ExecQuery("Select * from Win32_NTLogEvent Where Logfile = 'System' And EventCode = '6005' Or EventCode = '6006'") filePath="c:\startLog_" & FormateDateTime(Now,) & ".txt"
set fso=createobject("scripting.filesystemobject")
set file=fso.opentextfile(filePath,,true)
file.writeline "当前系统时间:" & Now
file.writeline "最近几次的开机和关机时间:" & vbNewLine
file.close
set file=fso.opentextfile(filePath,,true)
Wscript.Echo "开机日志已保存到:" & vbNewLine & filePath Flag =
For Each objEvent In colLoggedEvents
Flag = Flag +
msg = ""
If (flag < ) Then
If (flag Mod ) = Then
msg = "关机时间:" & UTCtoNow(objEvent.TimeWritten) & vbNewLine
Else
msg = "开机时间:" & UTCtoNow(objEvent.TimeWritten)
End If
file.writeline msg
End If
Next
file.close
CreateObject("Wscript.Shell").Run filePath,,ture Function UTCtoNow(nD)
If Not IsNull(nD) Then
Set SWDT = CreateObject("WbemScripting.SWbemDateTime")
SWDT.Value = nD
UTCtoNow = SWDT.GetVarDate(True)
End If
End Function Function FormateDateTime(strTime,ParaType)
select case ParaType
Rem Type 1 is YYYYMMDDHHmmss
case ""
strTime = year(strTime) & right( "" & month(strTime),) & right( "" & day(strTime),) & right( "00 " & hour(strTime),) & right( "00 " & minute(strTime),) & right( "00 " & second(strTime),)
Rem Type 2 is YYYYMMDD
case ""
strTime = year(strTime) & right( "" & month(strTime),) & right( "" & day(strTime),)
Rem Type 3 is YYYY-MM-DD
case ""
strTime = year(strTime) & "-"& right( "" & month(strTime),) & "-"& right( "" & day(strTime),)
Rem Type 4 is YYYY年MM月DD日
case ""
strTime = year(strTime) & "年"& right( "00 " & month(strTime),) & "月"& right( "" & day(strTime),)& "日 "
Rem Type 5 is YYYY-MM-DD HH:mm:ss
case ""
strTime = year(strTime) & "-"& right( "00 " & month(strTime),) & "-"& right( "" & day(strTime),) & " "& right( "00 " & hour(strTime),) & ": "& right( "00 " & minute(strTime),) & ": "& right( "00 " & second(strTime),)
end select
FormateDateTime = strTime
end Function

vbs查看系统开关机时间的更多相关文章

  1. win10中查看开关机时间及查看admin的RID的方法

    原文链接: https://www.toutiao.com/i6772133439593251339/ 打开系统的注册表 键盘输入win+r组合键出现运行窗口命令 输入regedit 按回车键,进入注 ...

  2. windows如何查看电脑开关机记录

    如何查看电脑开关机记录 (一)如果你只是想查看一下,从昨天关机到今天开机之间有没有人使用我的计算机,在“开始”菜单的运行”中输入“eventvwr.msc”,或者是按下"开始菜单" ...

  3. windows开关机时间记录

    1. 开机时间记录批处理文件,kai.bat @echo off echo %date% %time% 开机 >>D:\开关机记录\开关机时间.txt 2. 关机时间记录批处理文件,gua ...

  4. Linux常用命令(第二版) --系统开关机命令

    系统开关机命令 说明-服务器不会经常的关机,重启,没有故障,服务器不会关机.因此这些命令就显得不是很常用. 1.shutdown /usr/sbin/shutdown e.g. shutdown -h ...

  5. Windows XP 如何查看计算机开关机记录

    在Windows XP中,我们可以通过“事件查看器”的事件日志服务查看计算机的开.关机时间.因为事件日志服务会随计算机一起启动和关闭,并在事件日志中留下记录. 在这里有必要介绍两个ID号:6006和6 ...

  6. 查windows系统开关机记录

    https://blog.csdn.net/dufufd/article/details/53316079 者是按下"开始菜单"-"程序"-"管理工具 ...

  7. Linux——系统开关机指令简单学习笔记

    关机: 命令名称:shutdown 命令所在路径:/usr/sbin/shutdown 执行权限:root 语法:shutdown 功能描述:关机 范例:# shutdown -h now 重启: 命 ...

  8. windows系统开/关机日志位置

    邮件计算机=>管理 =>系统工具=>事件查看器=>Windows日志=>系统 过滤:关机:事件ID=6006 开机:事件ID=6005

  9. Win 7 通过事件管理器查看计算机开机关机时间

    控制面板-管理工具-事件查看器 视图中开机来源:Kernel-General 事件ID:13 关机来源:Kernel-General 事件ID:12

随机推荐

  1. $ 用python处理Excel文档(1)——用xlrd模块读取xls/xlsx文档

    本文主要介绍xlrd模块读取Excel文档的基本用法,并以一个GDP数据的文档为例来进行操作. 1. 准备工作: 1. 安装xlrd:pip install xlrd 2. 准备数据集:从网上找到的1 ...

  2. $UML统一建模语言简介

    (一)UML概述 1.面向对象软件开发的过程: (1)OOA(面向对象分析):建立分析模型并文档化. (2)OOD(面向对象设计):用面向对象思想对OOA的结果进行细化,得出设计模型. (3)OOP( ...

  3. java CountDownLatch 控制异步和同步

    应用场景举例: 执行A项目的方法,需要调用B项目.C项目.D项目的接口方法. 需求: 异步调用B.C.D项目的接口方法,且每个接口都调用结束后,A项目的方法才可以结束. 注:如果需要获取接口返回结果, ...

  4. Python自然语言处理系列之模拟退火算法

    1.基本概念 模拟退火算法(Simulated Annealing,SA)是一种模拟固体降温过程的最优化算法.其模拟的过程是首先将固体加温至某一温度,固体内部的粒子随温度上升慢慢变为无序的状态,内能增 ...

  5. busybox rmmod error — rmmod: chdir(2.6.25): No such file or directory

    busybox rmmod error rmmod: chdir(2.6.25): No such file or directory 1. install your modules in dir / ...

  6. myisam表修复

     数据库myisam引擎表损坏修复步骤:   1.进入到表目录文件下 # myisamchk -of comments.MYI 2. # myisamchk -r  comments.MYI 3. # ...

  7. 写时拷贝(Copy On Write)方案详解

    本文旨在通过对 写时拷贝 的四个方案(Copy On Write)分析,让大家明白写时拷贝的实现及原理. 关于浅拷贝与深拷贝,我在之前的博客中已经阐述过了  浅拷贝容易出现指针悬挂的问题,深拷贝效率低 ...

  8. K8s + Flannel 网络架构图

    这是Flannel官网给出的网络架构图 这是通过自己的理解画的逻辑结构图 查看bridge [root@node01 ~]# brctl show bridge name bridge id STP ...

  9. Owin and Startup class

    https://docs.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/owin-startup-class-detection ...

  10. 在移动端做查看日志信息的js

    Vconsole.js下载这个js引入需要使用的html文件,当运行到页面是就会在右下角显示提示,点击就出出现像pc端上的控制台页面 在线查看的网址 http://console.hongliang. ...