四.应用
计算机启动/关机脚本的用途很多,下面举三个比较典型的例子:
1.计算机启动和关机时间审核
(1)编写一个能够记录时间的脚本LogTime.vbs,内容如下:
'================================================
dim ArgObj,str,strtmp
Set ArgObj = WScript.Arguments
If ArgObj.Count < 1 Then
strtmp="无参数操作!"
else
select case ArgObj.Item(0)
case "startup"
strtmp=" 服务器启动."
case "shutdown"
strtmp=" 服务器关闭."
case else
strtmp=" 未知操作!参数:"+ArgObj.Item(0)
end select
end if
set fso=CreateObject("Scripting.FileSystemObject"
set tmp=fso.opentextfile("d:\log\logtime.txt",8,true)
str="["+cstr(now())+"] "+strtmp+chr(13)+chr(10)
tmp.write str
tmp.close
set tmp=nothing
set fso=nothing
'=================================================
这个脚本有两个参数tartup和shutdown.当用作启动脚本时,使用"startup"参数;当用做关机脚本时,使用"shutdown"参数.另外,脚本中使用了FileSystemObject对象,使用该脚本前请确保这个对象已经存在于你的计算机上.
(2)编写一个能恢复管理员密码的批处理文件admin.bat,内容只需要一条"net user"命令即可.如下:
net user administrator 12345678
这儿我们假设当前的管理员是administrator,将它的密码恢复为"12345678".将文件admin.bat保存到"E:\winnt\system32\GroupPolicy\Machine\Scripts\Startup"下,也就是故障计算机原来的"C:\winnt\system32\GroupPolicy\Machine\Scripts\Startup"下.