- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想做的是编写一个脚本,在我的计算机电池电量降至 20% 时创建一个消息框/弹出窗口。我希望消息框只出现一次 - 在我单击“确定”后它不应该再次出现,除非我为我的计算机充电并让它再次耗尽到 20%。
问题是当我的电池电量低于 20% 时,我的代码会导致每隔几分钟出现一次消息框。我的代码如下:
set oLocator = CreateObject("WbemScripting.SWbemLocator")
set oServices = oLocator.ConnectServer(".","root\wmi")
set oResults = oServices.ExecQuery("select * from batteryfullchargedcapacity")
for each oResult in oResults
iFull = oResult.FullChargedCapacity
next
while (1)
set oResults = oServices.ExecQuery("select * from batterystatus")
for each oResult in oResults
iRemaining = oResult.RemainingCapacity
bCharging = oResult.Charging
next
iPercent = Round((iRemaining / iFull) * 100)
if iRemaining and not bCharging and (iPercent < 21) and (iPercent > 10) Then msgbox "Your battery power is low (" & iPercent & "%). If you need to continue using your computer, either plug in your computer, or shut it down and then change the battery.",vbInformation, "Your battery is running low."
wscript.sleep 30000 ' 5 minutes
wend
我对 VBScript(和一般编程)还很陌生,所以我不太确定如何解决这个问题。
最佳答案
您需要有一个标志,例如一个名为 iShow 的变量。它以值 1 开始(可以弹出消息),单击确定后,iShow 将为零(不再显示)。下一次此标志的值为 1 是在电池电量超过 21% 时,因此当它再次下降到低于 21% 时,消息可以再次弹出,但只会弹出一次。这是代码:
set oLocator = CreateObject("WbemScripting.SWbemLocator")
set oServices = oLocator.ConnectServer(".","root\wmi")
set oResults = oServices.ExecQuery("select * from batteryfullchargedcapacity")
for each oResult in oResults
iFull = oResult.FullChargedCapacity
next
Dim iShow
iShow=1
while (1)
set oResults = oServices.ExecQuery("select * from batterystatus")
for each oResult in oResults
iRemaining = oResult.RemainingCapacity
bCharging = oResult.Charging
next
iPercent = Round((iRemaining / iFull) * 100)
if (iPercent>21) then iShow=1
if (iShow=1) and not bCharging and (iPercent < 21) Then
msgbox "Your battery power is low (" & iPercent & "%). If you need to continue using your computer, either plug in your computer, or shut it down and then change the battery.",vbInformation, "Your battery is running low."
iShow=0
end if
wscript.sleep 30000 ' 5 minutes
wend
关于windows - 谁能帮我修复 Windows 10 上的 VBS 脚本,该脚本在电池电量不足时显示警告/MsgBox?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69680278/
我使用 IBM Personal Communications 12.0.3.0 的宏记录器制作了一个凭据输入宏。它只是在调用时输入我的用户名和密码。 sub Credentials() Dim
该批处理更改了 vbs 代码,使其无法供 vbs 使用。我该如何解决这个问题? 批号: echo Const HIGH = 128 >> prio.vbs echo strComputer = "."
我有 2 个 vbs 文件。 A.vbs: Class test public a public b End Class B.vbs: Dim objShell Set objShell =
以下是我用来尝试在 IIS 6 中创建虚拟目录的条目: [Run] Filename: {tmp}\cscript.exe mkvirtdir.vbs; Parameters: "-c LocalHo
核心vbs代码 ? 1
对于vbs中ping的实现可以通过两种方式 : 1、调用系统ping命令; 2、使用wmi查询pingstate类处理。 1、调用系统ping命令
在看vb开发,看到二维数组时突发奇想用二维数组作为游戏关卡; 1. 选择操作: 游戏开始时会提示选择注册, 登录, 退出三种选项, 2.注册: 注册成功会将用户账户与密码存入用户数据txt文档中
复制指定文件到指定目录下 核心代码 ? 1
复制代码 代码如下: On Error Resume Next Dim WshShell, QQPath, QQselect set wshshell=createobject("
运行前请确定你的电脑安装了word。 复制代码 代码如下: i=0 set wshshell=createobject("wscript.shell") Set objWo
参考代码一: 复制代码 代码如下: Function DeleteLog( ) Dim objFSO, objFolder, strPath,
挺实用的一段代码,用来深入学习vbs,确实不错咯。 复制代码 代码如下: On Error Resume Next '忽略所有错误 Dim filename '声明变量 Di
话说还是闲来练手,初步实现了自己认为的“多线程”下载。(至于是不是多线程,可以参考12楼链接) 为避免冗余,省了一些错误检查。我觉得没多大实际用途,有兴趣的兄弟一起学习讨论呗。欢迎大家指正: 复制
复制代码 代码如下: set oDOM = WScript.GetObject("http://ipseeker.cn//") flag=0 for i=1 to 10 &n
复制代码 代码如下: on error resume next url = " http://www.bathome.net/logging.php?action=login"
效果图: 代码都封装成函数了,方便调用: 复制代码 代码如下: Key = "www-enun-net" '不要用数字
打开狗狗影视,搜索自己需要的资源,资源类型选:电驴,如下图: 我找到一个 19.75gb 的: 点开它,出现如下图的界面,可以看到正常下载地址已被屏蔽。我们复制地址栏中的网址,备用。
最近相关的备份比较频繁,为了校验文件的完整性,老是要打开某文件HASH校验工具,比较麻烦,于是乎写了这个东东,文件较大时计算有点慢,文件的MD5值保存在剪贴板!效果如图: 使用方法: 1.先
CMD当前路径 复制代码 代码如下: test = createobject("Scripting.FileSystemObject").GetF
For Next 语句的基本结构为: 复制代码 代码如下: For counter = start To end [Step step] [statements] [Exit For] [st
我是一名优秀的程序员,十分优秀!