【发布时间】:2015-07-20 01:56:48
【问题描述】:
我有一个简单的 VB 脚本,它可以让我在我希望我的电脑自行关闭之前的几分钟内输入,然后它会自动关闭。那工作得很好。在我擦除我的电脑后,脚本不再按预期运行,而是在我输入关机前的分钟数后显示一个空白的 cmd 窗口,并再次显示输入框(询问关机前的分钟数)。
关于为什么它不能正常工作以及为什么它以前有效但现在无效的任何想法?我是否需要某个可能我没有重新安装的 Microsoft 软件包?
代码:
Dim a
Dim oShell
a=inputbox("After how many minutes would you like to shut down your PC? Enter cancel to cancel a previous shutdown")
Set oShell = WScript.CreateObject ("WScript.Shell")
if a = "cancel" then
oShell.run "cmd.exe /c shutdown /a"
elseif a = "" then
MsgBox"Please enter after how many minutes you would like to turn off this PC",0+16,"Enter a number"
elseif a = "0" then
b=msgbox("Are you sure you want to shut down this PC immediately?",4+32,"Shut down immediately?")
if b = "6" then
oShell.run "cmd.exe /c shutdown /s /f"
end if
else
oShell.run "cmd.exe /c shutdown /s /t " & (a * 60)
end if
编辑:从其目录运行脚本按预期工作,但从快捷方式运行 VBScript(正如我一直在做的那样)不起作用并产生上述结果。
编辑:脚本本身也无法在我的桌面上正常运行,但在我存储脚本的文件夹中运行良好。
【问题讨论】:
-
您的代码中没有任何内容会导致脚本循环。
-
而且它不应该循环。但它确实如此,只要我输入一个值并按回车键。弹出一个空白的cmd窗口,再次显示输入框