PC擦除后,简单关机脚本无法正常运行

时间:2015-07-19 03:22:45

标签: vbscript shutdown

我有一个简单的VB脚本,让我可以在我想让我的电脑自动关闭之前输入分钟数,然后它会自动关闭。这工作得很好。在我擦拭PC后,脚本不再按预期运行,而是在我输入关机前的分钟数后显示空白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(就像我一直在做的那样)不起作用并产生上述结果。

编辑:脚本本身也无法在我的桌面上正常运行,但在我存储脚本的文件夹中运行良好。

1 个答案:

答案 0 :(得分:1)

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

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

重命名您的VBScript或将cmd.exe /c shutdown.exe更改为 Dbcon.Open() Dim query As String Dim dbup As New OleDbCommand For x As Integer = 0 To IncomingMailDGV.Rows.Count - 1 Dim received As String = IncomingMailDGV.Rows(x).Cells(0).Value Dim subject As String = IncomingMailDGV.Rows(x).Cells(1).Value Dim contents As String = IncomingMailDGV.Rows(x).Cells(2).Value query = "SELECT ReceivedDateTime, Subject, MessageContents FROM IncomingAlerts WHERE ReceivedDateTime = @ReceivedDateTime AND MessageContents =@MessageContents" dbup = New OleDbCommand(query, Dbcon) dbup.Parameters.AddWithValue("ReceivedDateTime", received) dbup.Parameters.AddWithValue("MessageContents", contents) Dim readinputs As OleDbDataReader readinputs = dbup.ExecuteReader() If readinputs.HasRows = False Then Dim InsertData As String InsertData = "INSERT INTO IncomingAlerts(ReceivedDateTime, Subject, MessageContents) Values (@ReceivedDateTime, @Subject, @MessageContents)" dbup.Parameters.AddWithValue("ReceivedDateTime", received) dbup.Parameters.AddWithValue("Subject", subject) dbup.Parameters.AddWithValue("MessageContents", contents) dbup = New OleDbCommand(InsertData) With dbup .CommandText = InsertData .Connection = Dbcon .ExecuteNonQuery() End With End If Next ,问题就会消失。