views:

317

answers:

2

Hi guys. Found this Reboot Vista.vbs script on a number of forums. Seems like the whole post ( text including the code ) was posted on many forums. So I don't know who the original author is. Heres the code here:

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

It is supposed to reboot Vista, and once it is rebooted, show the time it took to reboot. It reboots fine and everything, but the dialog box doesn't pop up. I have to manually click on the script again for the time to appear ? I think that defeats the purpose of the script don't you ?

Any help would be much appreciated fellas.

A: 

Maybe you are getting an error which is preventing the display of the message box? This line you have at the start of the script will cause it to ignore all errors:

On Error Resume Next

You should simply delete this line, then run it again and see what is happening.

1800 INFORMATION
+1  A: 

You cannot have spaces in the regpath: Change "Curr e ntVersion" to "CurrentVersion"

This row:

Wsh.RegWrite KeyB, PathFile, "REG_SZ"

will register the script to autostart with windows if the PathFile and KeyB is correct, but with spaces in "Curr e ntVersion" it will not work.

Stefan
Well Done to you Stefan !I overlooked that part . must of been from when I copied and pasted it from the forum, I don't know. But thank you anyway .I don't have access to an XP system to test. But does this work for XP as well ? If not, what will it take to get it to work on both vista and xp ? Or even a seperate script for each OS.Thanks Stefan !
Methical
What I can see it does not do anyting Vista specific. It should work on XP too.
Stefan
And to clarify, of course you can have spaces in the regpath, but not in wrong places. ;)
Stefan