gpt4 book ai didi

windows - 如何每 2 分钟更新一次 Windows 注册表?

转载 作者:可可西里 更新时间:2023-11-01 11:35:45 25 4
gpt4 key购买 nike

我正在用 VBA 编写一个脚本,它将监视注册表值,如果它发生更改,脚本将覆盖它。到目前为止,我编写了一个脚本来检查注册表中的值并将其更新为给定值。但我的问题是如何每 2 分钟或值更改时更新一次注册表?请帮忙!!!

On Error Resume Next
HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Control Panel\Desktop"
ValueName = "ScreenSaveActive"
objReg.GetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
objReg.CreateKey HKEY_CURRENT_USER, strKeyPath
If IsNull(strValue) Then
Wscript.Echo "The value is either Null or could not be found in the registry."
Else
Wscript.Echo "Value: ", strValue
strValue = "1"
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
Wscript.Echo "Value after change ", strValue
End If

问候,厄尼

最佳答案

只要把你的代码放在一个循环中,并告诉它在每次循环之间休眠 2 分钟,所以这样的事情可能会起作用:

Do While 1

...
[your code here]
...

WScript.Sleep(120 * 1000) ' 120 seconds in 2 minutes and it expects milliseconds
Loop

但是如果该值为空,那么继续下去可能没有任何意义,因此可能值得在 Echo 之后添加一行 Exit Do about如果是这种情况,则停止循环为 null。

不过请注意,您使用的是 VBscript,而不是 VBA(它们很相似,但仍然是不同的语言)。

关于windows - 如何每 2 分钟更新一次 Windows 注册表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11544466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com