中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 记录开机和关机时间及机器运行时间
作者:
标题: 记录开机和关机时间及机器运行时间 上一主题 | 下一主题
zjl5
初级用户





积分 82
发帖 15
注册 2007-5-26
状态 离线
『楼 主』:  记录开机和关机时间及机器运行时间

::记录开机和关机时间及机器运行时间,傻瓜式安装,不用手工了.呵呵..
@echo off
chcp|find "936" >nul 2>nul
if "%ERRORLEVEL%"=="1" (echo 您的操作系统不是中文版!"可能"无法记录开关机时间.) else (echo 您的操作系统是中文版!)
ver|find "2000" > nul 2>nul
if "%ERRORLEVEL%"=="0" (echo 你的操作系统是Windows 2000!"可能"无法记录开关机时间.&goto :log)
ver|find "XP" > nul 2>nul
if "%ERRORLEVEL%"=="0" (echo 你的操作系统是Windows xp!&goto :log)
echo 您的操作系统不是Windows 2000或者Windows XP,"可能"无法记录开关机时间.
:log
if exist %windir%\system32\systeminfo.exe (
echo 找到所需文件,开始安装!
) else (
echo 找不到所需文件,日志将失去部分记录.
)
::记录开机时间
echo @echo off>logon.bat
echo echo ------------------------------------------^>^>%%windir%%\Logon.txt>>logon.bat
echo echo 登陆时间:%%date%%,%%time%% ^>^>%%windir%%\Logon.txt>>logon.bat
echo echo 登陆用户名:%%USERNAME%%^>^>%%windir%%\Logon.txt>>logon.bat
echo exit>>logon.bat
::记录关机时间
echo @echo off>logoff.bat
echo echo 请稍候...>>logoff.bat
echo for /f "skip=11 delims=秒" %%%%%i in ('systeminfo') do (>>logoff.bat
echo    echo "%%%%i秒" ^>^>%%windir%%\Logon.txt>>logoff.bat
echo    echo 注消时间:%%date%%,%%time%% ^>^>%%windir%%\Logon.txt>>logoff.bat
echo    echo ------------------------------------------^>^>%%windir%%\Logon.txt>>logoff.bat
echo    echo.^>^>%%windir%%\Logon.txt>>logoff.bat
echo    exit>>logoff.bat
echo    )>>logoff.bat
copy logon.bat d:\ & copy logoff.bat d:\
pause
::看看有没有成功,判断一下,顺便加上属性.保险...
:att
if exist d:\logon.bat (attrib +a +s +r +h d:\logon.bat) else (goto :att)
if exist d:\logoff.bat (attrib +a +s +r +h d:\logoff.bat) else (goto :att)
echo 文件创建成功!
echo 加入注册表,这是成功的一部分.windows发出提示时请点击确定.
echo Windows Registry Editor Version 5.00>>log.reg
echo [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts]>>log.reg
echo [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logoff]>>log.reg
echo [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logoff\0]>>log.reg
echo "GPO-ID"="LocalGPO">>log.reg
echo "SOM-ID"="Local">>log.reg
echo "FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\User">>log.reg
echo "DisplayName"="Local Group Policy">>log.reg
echo "GPOName"="Local Group Policy">>log.reg
echo [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logoff\0\0]>>log.reg
echo "Script"="D:\\logoff.bat">>log.reg
echo "Parameters"="">>log.reg
echo "ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00>>log.reg
echo [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logon]>>log.reg
echo [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logon\0]>>log.reg
echo "GPO-ID"="LocalGPO">>log.reg
echo "SOM-ID"="Local">>log.reg
echo "FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\User">>log.reg
echo "DisplayName"="Local Group Policy">>log.reg
echo "GPOName"="Local Group Policy">>log.reg
echo [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logon\0\0]>>log.reg
echo "Script"="D:\\logon.bat">>log.reg
echo "Parameters"="">>log.reg
echo "ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00>>log.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\S-1-5-21-1960408961-115176313-725345543-1004\Scripts]>>log.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\S-1-5-21-1960408961-115176313-725345543-1004\Scripts\Logoff]>>log.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\S-1-5-21-1960408961-115176313-725345543-1004\Scripts\Logoff\0]>>log.reg
echo "GPO-ID"="LocalGPO">>log.reg
echo "SOM-ID"="Local">>log.reg
echo "FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\User">>log.reg
echo "DisplayName"="Local Group Policy">>log.reg
echo "GPOName"="Local Group Policy">>log.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\S-1-5-21-1960408961-115176313-725345543-1004\Scripts\Logoff\0\0]>>log.reg
echo "Script"="D:\\logoff.bat">>log.reg
echo "Parameters"="">>log.reg
echo "ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00>>log.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\S-1-5-21-1960408961-115176313-725345543-1004\Scripts\Logon]>>log.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\S-1-5-21-1960408961-115176313-725345543-1004\Scripts\Logon\0]>>log.reg
echo "GPO-ID"="LocalGPO">>log.reg
echo "SOM-ID"="Local">>log.reg
echo "FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\User">>log.reg
echo "DisplayName"="Local Group Policy">>log.reg
echo "GPOName"="Local Group Policy">>log.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\S-1-5-21-1960408961-115176313-725345543-1004\Scripts\Logon\0\0]>>log.reg
echo "Script"="D:\\logon.bat">>log.reg
echo "Parameters"="">>log.reg
echo "ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00>>log.reg
echo [HKEY_USERS\S-1-5-21-1960408961-115176313-725345543-1004\Software\Policies\Microsoft\Windows\System\Scripts]>>log.reg
echo [HKEY_USERS\S-1-5-21-1960408961-115176313-725345543-1004\Software\Policies\Microsoft\Windows\System\Scripts\Logoff]>>log.reg
echo [HKEY_USERS\S-1-5-21-1960408961-115176313-725345543-1004\Software\Policies\Microsoft\Windows\System\Scripts\Logoff\0]>>log.reg
echo "GPO-ID"="LocalGPO">>log.reg
echo "SOM-ID"="Local">>log.reg
echo "FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\User">>log.reg
echo "DisplayName"="Local Group Policy">>log.reg
echo "GPOName"="Local Group Policy">>log.reg
echo [HKEY_USERS\S-1-5-21-1960408961-115176313-725345543-1004\Software\Policies\Microsoft\Windows\System\Scripts\Logoff\0\0]>>log.reg
echo "Script"="D:\\logoff.bat">>log.reg
echo "Parameters"="">>log.reg
echo "ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00>>log.reg
echo [HKEY_USERS\S-1-5-21-1960408961-115176313-725345543-1004\Software\Policies\Microsoft\Windows\System\Scripts\Logon]>>log.reg
echo [HKEY_USERS\S-1-5-21-1960408961-115176313-725345543-1004\Software\Policies\Microsoft\Windows\System\Scripts\Logon\0]>>log.reg
echo "GPO-ID"="LocalGPO">>log.reg
echo "SOM-ID"="Local">>log.reg
echo "FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\User">>log.reg
echo "DisplayName"="Local Group Policy">>log.reg
echo "GPOName"="Local Group Policy">>log.reg
echo [HKEY_USERS\S-1-5-21-1960408961-115176313-725345543-1004\Software\Policies\Microsoft\Windows\System\Scripts\Logon\0\0]>>log.reg
echo "Script"="D:\\logon.bat">>log.reg
echo "Parameters"="">>log.reg
echo "ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00Windows>>log.reg
echo [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts]>>log.reg
echo [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logoff]>>log.reg
echo [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logoff\0]>>log.reg
echo "GPO-ID"="LocalGPO">>log.reg
echo "SOM-ID"="Local">>log.reg
echo "FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\User">>log.reg
echo [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logoff\0\0]>>log.reg
echo "Script"="D:\\logoff.bat">>log.reg
echo "Parameters"="">>log.reg
echo "ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00>>log.reg
echo [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logon]>>log.reg
echo [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logon\0]>>log.reg
echo "GPO-ID"="LocalGPO">>log.reg
echo "SOM-ID"="Local">>log.reg
echo "FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\User">>log.reg
echo [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logon\0\0]>>log.reg
echo "Script"="D:\\logon.bat">>log.reg
echo "Parameters"="">>log.reg
echo "ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00>>log.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group>>log.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group>>log.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group>>log.reg
echo "GPO-ID"="LocalGPO">>log.reg
echo "SOM-ID"="Local">>log.reg
echo "FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\User">>log.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group>>log.reg
echo "Script"="D:\\logoff.bat">>log.reg
echo "Parameters"="">>log.reg
echo "ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00>>log.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group>>log.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group>>log.reg
echo "GPO-ID"="LocalGPO">>log.reg
echo "SOM-ID"="Local">>log.reg
echo "FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\User">>log.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group>>log.reg
echo "Script"="D:\\logon.bat">>log.reg
echo "Parameters"="">>log.reg
echo "ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00>>log.reg
echo [HKEY_USERS\S-1-5-21-1960408961-115176313-725345543-1004\Software\Policies\Microsoft\Windows\System\Scripts]>>log.reg
echo [HKEY_USERS\S-1-5-21-1960408961-115176313-725345543-1004\Software\Policies\Microsoft\Windows\System\Scripts\Logoff]>>log.reg
echo [HKEY_USERS\S-1-5-21-1960408961-115176313-725345543-1004\Software\Policies\Microsoft\Windows\System\Scripts\Logoff\0]>>log.reg
echo "GPO-ID"="LocalGPO">>log.reg
echo "SOM-ID"="Local">>log.reg
echo "FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\User">>log.reg
echo [HKEY_USERS\S-1-5-21-1960408961-115176313-725345543-1004\Software\Policies\Microsoft\Windows\System\Scripts\Logoff\0\0]>>log.reg
echo "Script"="D:\\logoff.bat">>log.reg
echo "Parameters"="">>log.reg
echo "ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00>>log.reg
echo [HKEY_USERS\S-1-5-21-1960408961-115176313-725345543-1004\Software\Policies\Microsoft\Windows\System\Scripts\Logon]>>log.reg
echo [HKEY_USERS\S-1-5-21-1960408961-115176313-725345543-1004\Software\Policies\Microsoft\Windows\System\Scripts\Logon\0]>>log.reg
echo "GPO-ID"="LocalGPO">>log.reg
echo "SOM-ID"="Local">>log.reg
echo "FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\User">>log.reg
echo [HKEY_USERS\S-1-5-21-1960408961-115176313-725345543-1004\Software\Policies\Microsoft\Windows\System\Scripts\Logon\0\0]>>log.reg
echo "Script"="D:\\logon.bat">>log.reg
echo "Parameters"="">>log.reg
echo "ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00>>log.reg
call log.reg
echo 完成啦!在你的系统目录(一般在c:\windows)下有一个logon.txt文件,这个文件里记录了开机和关机的具体时间及每次开机运行时间.
echo 按任意键退出...
pause>nul


2007-5-28 01:18
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
scriptor
银牌会员




积分 1187
发帖 555
注册 2006-12-21
状态 离线
『第 2 楼』:  

其实用 eventquery不就好了么?

2007-9-15 20:00
查看资料  发短消息 网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: