vbs查看系统开关机时间
如何获取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查看系统开关机时间的更多相关文章
- win10中查看开关机时间及查看admin的RID的方法
原文链接: https://www.toutiao.com/i6772133439593251339/ 打开系统的注册表 键盘输入win+r组合键出现运行窗口命令 输入regedit 按回车键,进入注 ...
- windows如何查看电脑开关机记录
如何查看电脑开关机记录 (一)如果你只是想查看一下,从昨天关机到今天开机之间有没有人使用我的计算机,在“开始”菜单的运行”中输入“eventvwr.msc”,或者是按下"开始菜单" ...
- windows开关机时间记录
1. 开机时间记录批处理文件,kai.bat @echo off echo %date% %time% 开机 >>D:\开关机记录\开关机时间.txt 2. 关机时间记录批处理文件,gua ...
- Linux常用命令(第二版) --系统开关机命令
系统开关机命令 说明-服务器不会经常的关机,重启,没有故障,服务器不会关机.因此这些命令就显得不是很常用. 1.shutdown /usr/sbin/shutdown e.g. shutdown -h ...
- Windows XP 如何查看计算机开关机记录
在Windows XP中,我们可以通过“事件查看器”的事件日志服务查看计算机的开.关机时间.因为事件日志服务会随计算机一起启动和关闭,并在事件日志中留下记录. 在这里有必要介绍两个ID号:6006和6 ...
- 查windows系统开关机记录
https://blog.csdn.net/dufufd/article/details/53316079 者是按下"开始菜单"-"程序"-"管理工具 ...
- Linux——系统开关机指令简单学习笔记
关机: 命令名称:shutdown 命令所在路径:/usr/sbin/shutdown 执行权限:root 语法:shutdown 功能描述:关机 范例:# shutdown -h now 重启: 命 ...
- windows系统开/关机日志位置
邮件计算机=>管理 =>系统工具=>事件查看器=>Windows日志=>系统 过滤:关机:事件ID=6006 开机:事件ID=6005
- Win 7 通过事件管理器查看计算机开机关机时间
控制面板-管理工具-事件查看器 视图中开机来源:Kernel-General 事件ID:13 关机来源:Kernel-General 事件ID:12
随机推荐
- linux中环境变量的用法
Linux操作系统下三种配置环境变量的方法[转] 在linux下做开发首先就是需要配置环境变量,下面以配置java环境变量为例介绍三种配置环境变量的方法. 1.修改/etc/profile文件 如果你 ...
- 04_Apache Hadoop 生态系统
内容提纲: 1)对 Apache Hadoop 生态系统的认识(Hadoop 1.x 和 Hadoop 2.x) 2) Apache Hadoop 1.x 框架架构原理的初步认识 3) Apache ...
- Shell编程之Linux信号及信号跟踪
一.Linux信号 1.什么是信号? Linux信号是由一个整数构成的异步消息,它可以由某个进程发给其他进程,也可以在用户按下特定键发生某种异常事件时,由系统发给某个进程. 2.信号列表 [root@ ...
- 20145239杜文超《网络攻防》- MSF基础应用
20145239杜文超<网络攻防>- MSF基础应用 基础问题回答 1.用自己的话解释什么是exploit,payload,encode? exploit:实现攻击行为的主体,但没有载荷只 ...
- SpringBoot Mybatis keyProperty和useGeneratedKeys的作用
在使用mybatis时,常常会出现这种需求: 当主键是自增的情况下,添加一条记录的同时,其主键是不能被使用的(为空),但是有时我们需要该主键,这时我们该如何处理呢?这时我们只需要在其对应xml中加入以 ...
- Adroid真机调试
几次想学Android,都因为启动模拟器调试时太慢而放弃. 今天终于搞通了真机调试,记录一下: 1)USB线把手机和电脑连接. 2)Adroid手机启用USB调试. 3)命令行运行 adb devic ...
- MongoDB快速入门(三)- 集合
创建集合 MongoDB 的 db.createCollection(name, options) 用于创建集合. 在命令中, name 是要创建集合的名称. Options 是一个文档,用于指定集合 ...
- 1.linux源码安装nginx
从官网下载nginx.tar.gz源码包 拷贝至Linux系统下进行解压 tar -zxvf nginx.tar.gz 进入解压后的目录,需要./configure,此步骤会报多个错,比如没有安装gc ...
- freemarker 异常处理
SSH2处理方案: freemarker文件如果出错,网站的前台页面会报出很明显的错误-焦黄的背景,血红的文字,很不利于用户体验的.如何修改这个问题呢?首先需要在struts.xml配置文件里添加下面 ...
- linux vim vi编辑时撤销输入操作
linux vim vi编辑时撤销输入操作 1,esc退出输入状态 2,u 撤销上次操作 3,ctrl+r 恢复撤销