批处理中使用vbs

本文介绍了如何在批处理中使用VBScript进行系统服务管理和服务状态查询,包括列举自启动和正在运行的服务,显示系统启动时间以及进行浮点运算。通过创建vbs文件并执行,实现了批处理命令与VBScript的结合应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

批处理中使用vbs

1 列举自启动的服务

@echo for each sc in getobject("winmgmts:\\.\root\cimv2:win32_service").instances_ >sc.vbs
@echo if sc.startmode="Auto" then wscript.echo sc.name^&" - "^&sc.pathname >>sc.vbs
@echo next >>sc.vbs & cscript //nologo sc.vbs & del sc.vbs

2 列举正在运行的服务

@echo for each sc in getobject("winmgmts:\\.\root\cimv2:win32_service").instances_ >sc.vbs
@echo if sc.state="Running" then wscript.echo sc.name^&" - "^&sc.pathname >>sc.vbs
@echo next >>sc.vbs & cscript //nologo sc.vbs & del sc.vbs

3 显示系统最后一次启动的时间

@echo for each os in getobject _ >bt.vbs
@echo ("winmgmts:\\.\root\cimv2:win32_operatingsystem").instances_ >>bt.vbs
@echo wscript.echo os.lastbootuptime:next >>bt.vbs & cscript //nologo bt.vbs & del bt.vbs

显示结果的格式是:
yyyymmddHHMMSS******ZZZZ
_年_月日时分秒_微秒_时区

变形为获取系统的时区
@echo for each os in getobject _ >bt.vbs
@echo ("winmgmts:\\.\root\cimv2:win32_operatingsystem").instances_ >>bt.vbs
@echo wscript.echo os.lastbootuptime:next >>bt.vbs & cscript //nologo bt.vbs >tempTime.txt & del bt.vbs

SET /p LastBootUpTime=<tempTime.txt & del tempTime.txt
SET TimeZone=%LastBootUpTime:~21%

4 利用vbs进行浮点运算
@echo off
set a=8.878
set b=9.4

echo aa=%a%>hero.vbs
echo bb=%b%>>hero.vbs
echo sum=aa+bb>>hero.vbs
echo msgbox sum>>hero.vbs

call hero.vbs
del hero.vbs
pause

完!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值