【问题标题】:Simple shutdown script does not function properly after PC wipePC 擦除后简单的关机脚本无法正常运行
【发布时间】: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窗口,再次显示输入框

标签: vbscript shutdown


【解决方案1】:

您将脚本命名为shutdown.vbs 并在工作目录设置为包含该脚本的目录的情况下运行它。通过运行oShell.Run "cmd.exe /c shutdown ...",您的脚本实际上是在调用自己。

如果您调用命令shutdown(没有路径和扩展名),系统将在%PATH% 环境变量中列出的目录中查找具有%PATHEXT% 中列出的扩展名之一的文件。第一场比赛获胜。 由于在 Windows 上,当前目录首先出现在 %PATH% 中,因此文件 %CD%\shutdown.vbs 位于 %windir%\system32\shutdown.exe 之前。

要么重命名您的 VBScript,要么将 cmd.exe /c shutdown 更改为 cmd.exe /c shutdown.exe,问题就会消失。

【讨论】:

    猜你喜欢
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 2012-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-20
    相关资源
    最近更新 更多