当前位置:DOS资源站资料中心VBS脚本 → vbs实现更改显示操作系统列表的时间2008-05-26 16:31

vbs实现更改显示操作系统列表的时间2008-05-26 16:31

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2008-5-26 17:49:58

'本脚本利用更改boot.ini文件的timeout的值来实现更改显示操作系统列表的时间
'script by breakan
option explicit
dim fso,open,ws,wsenv
dim attrib,boottime,bootini,timeline,boot_inipath,yon

set fso=createobject("scripting.filesystemobject")
set ws=wscript.createobject("wscript.shell")
set wsenv=ws.environment("PROCESS")
boot_inipath=wsenv("HOMEDRIVE") & "\boot.ini"

do
on error resume next
boottime=inputbox("请输入显示操作系统列表的时间:" & vbcr & "一定要是数字并且是整数,>=0,<=999","boot.ini","5")
if boottime="" and isnumeric(cint(boottime)) then
    yon=msgbox("您没有填写任何正确的数字要重新填写吗?",4+32,"boot.ini")
    if yon=7 then wscript.quit
else
    exit do
end if
loop

call fileattrib '调用fileattrib过程更改boot.ini文件的属性

'更改boot.ini文件的timeout值
set open=fso.opentextfile(boot_inipath,1)
open.skipline   '文件指针跳第二行,因为第二行就是timeout=那一行.
timeline=open.readline    '读取第二行
open.close
set open=fso.opentextfile(boot_inipath,1)
bootini=replace(open.readall,timeline,"timeout=" & boottime)    '更改timeout的值.
open.close
set open=fso.opentextfile(boot_inipath,2)   '把更改后的内容写入boot.ini文件.
open.write bootini
open.close

call fileattrib   '调用fileattrib过程改回boot.ini文件的属性
msgbox "已更改^-^"

'设置boot.ini文件的属性,这样才能改文件的内容
sub fileattrib
dim f
set f=fso.getfile(boot_inipath) '获取boot.ini文件
if f.attributes>0 and f.attributes<>32 then '因为修改boot.ini文件后,属性就自动变成32了,所以要不等于32
    attrib=f.attributes
    f.attributes=f.attributes-f.attributes   '把boot.ini文件的属性设置为0
else
    f.attributes=attrib   '把boot.ini文件的属性还原
end if
end sub