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
随机推荐
- 【转载】OPENWRT入门之四------openwrt命令行模式命令及其工具
连接来源http://bbs.xiaomi.cn/thread-9734746-1-1.html 需要学会用ssh登录路由器用linux命令查看.ps 命令查看当前系统运行的进程信息free 命令查看 ...
- p2p网络中的NAT穿透技术----常见NAT穿越解决方案
转:http://blog.csdn.net/cllzw/article/details/46438257 常见NA丁穿越解决方案 NAT技术在缓解IPv4地址紧缺问题.构建防火墙.保证网络安全等方面 ...
- 三 ip dns等配置
一IP.端口.协议基本概念 ip的简单概念 互联网上的计算机,都会有一个唯一的32位的地址,ip地址 我们访问服务器,就必须通过ip地址 局域网里也有预留的ip地址 192/10/172.居于王的i ...
- 20145240 《Java程序设计》第八周学习总结
20145240 <Java程序设计>第八周学习总结 教材学习内容总结 15.1日志 15.1.1日志API简介 java.util.logging包提供了日志功能相关类与接口,不必额外配 ...
- .NET自带泛型委托方法Func、Action和Predicate
Func.Action和Predicate是.NET自带的3个泛型委托方法,三个方法的区别其实并不大,要强行给混着用也是可以的,但是我们是有追求的人,把道理讲清楚总是好的. 一.Func是有返回值的方 ...
- Docker 共享存储解决方案Rex-Ray
github地址:https://github.com/rexray/rexray 安装: curl -sSL https://rexray.io/install | sh - 生成配置文件: htt ...
- 3.mysql多表
这篇主要总结mysql的建表规则. 01.多表_建表的原则: 需求:创建一个表可以存储学员信息:学员编号,姓名,性别,年龄,科目 1).原则: 1.保证表中的一列,只记 ...
- 分布式服务管理zookeeper的java api
zookeeper是一个分布式服务管理工具,本身具备高可用性,很多知名分布式系统入hadoop.Hbase等都采用zk管理. 常见的两个应用场景:1.服务的注册与发现 2.集群统一配置 下面看一下使用 ...
- thinkphp判断更新是否成功
如何判断一个更新操作是否成功 $Model = D('Blog'); $data['id'] = 10; $data['name'] = 'update name'; $result = $Model ...
- Codeforces Round #275 (Div. 2) D
题意 : 一个数组 给出m个限制条件 l r z 代表从l 一直 & 到 r 为 z 问能否构造出这种数组 如果可以 构造出来 因为 n m 都是1e5 而l r 可能输入进去就超时了 所以 ...