Scripting 我找到了这个重新启动Vista.vbs脚本。你能帮忙吗?

Scripting 我找到了这个重新启动Vista.vbs脚本。你能帮忙吗?,scripting,vbscript,windows-vista,Scripting,Vbscript,Windows Vista,在多个论坛上找到此重新启动Vista.vbs脚本。似乎整个帖子(包括代码的文本)都发布在了很多论坛上。所以我不知道原作者是谁。下面是代码: Option Explicit On Error Resume Next Dim Wsh, Time1, Time2, Result, PathFile, MsgResult, MsgA, AppName, KeyA, KeyB, TimeDiff MsgA = "Warning! Close all running programs and click o

在多个论坛上找到此重新启动Vista.vbs脚本。似乎整个帖子(包括代码的文本)都发布在了很多论坛上。所以我不知道原作者是谁。下面是代码:

Option Explicit
On Error Resume Next
Dim Wsh, Time1, Time2, Result, PathFile, MsgResult, MsgA, AppName, KeyA, KeyB, TimeDiff
MsgA = "Warning! Close all running programs and click on OK."
KeyA = "HKEY_CURRENT_USER\Software\RestartTime\"
KeyB = "HKEY_CURRENT_USER\Software\Microsoft\Windows\Curr e ntVersion\Run\RestartTime"
AppName = "Boot Up Time"
Set Wsh = CreateObject("WScript.Shell")
PathFile = """" & WScript.ScriptFullName & """"
Result = wsh.RegRead(KeyA & "Times")
if Result = "" then
MsgResult = Msgbox (MsgA, vbOKCancel, AppName)
If MsgResult = vbcancel then WScript.Quit
Wsh.RegWrite KeyA & "Times", left(Time,8), "REG_SZ"
Wsh.RegWrite KeyB, PathFile, "REG_SZ"
Wsh.Run "cmd /c Shutdown -r -t 00", false, 0
else
Wsh.RegDelete KeyA & "Times"
Wsh.RegDelete KeyA
Wsh.RegDelete KeyB
TimeDiff = DateDiff("s",Result,left(Time,8))
MsgBox "Your system reboots in " & TimeDiff & " seconds", VbInformation, AppName
end if
wscript.Quit
它应该重新启动Vista,一旦重新启动,显示重新启动所花的时间。 它可以重新启动,但对话框不会弹出。我必须再次手动单击脚本才能显示时间?我认为这违背了剧本的目的,不是吗


非常感谢各位的帮助。

也许您遇到了一个阻止显示消息框的错误?脚本开头的这一行将导致脚本忽略所有错误:

On Error Resume Next

您只需删除这一行,然后再次运行它,看看发生了什么。

regpath中不能有空格:将“Curr e ntVersion”更改为“CurrentVersion”

此行:

Wsh.RegWrite KeyB, PathFile, "REG_SZ"

如果路径文件和KeyB正确,将在windows中注册脚本以自动启动,但在“Curr e ntVersion”中使用空格将不起作用。

我想KeyB应该是
。\CurrentVersion\…
,而不是
。\Curr e ntVersion\…
。海伦,这是答案,不是注释;)@史蒂芬:嗯,也许吧,但你不辞辛劳地给出了一个像样的解释,说明了什么是错的,为什么是错的,所以我不介意你打勾。;-)干得好,斯蒂芬!我忽略了那部分。一定是从我从论坛上复制粘贴的时候开始的,我不知道。不过还是谢谢你。我无法访问XP系统进行测试。但这是否也适用于XP?如果没有,需要什么才能让它同时在vista和xp上工作?甚至每个操作系统都有一个单独的脚本。谢谢Stefan!我所能看到的是,它并没有做任何特定于Vista的事情。它应该也适用于XP。为了澄清这一点,您当然可以在regpath中使用空格,但不能在错误的位置使用。;)