关闭

自动关机的小VBS程序

963人阅读 评论(1) 收藏 举报

<script language="vbs">
Option Explicit
Dim ws, Title, ErrMsg
Set ws = CreateObject("Wscript.Shell")
Title = "Windows Shutdown Timer"
Dim oWMI, oOS, obj

On Error Resume Next
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!//./root/cimv2")
If Err Then
  MsgBox "Your computer does not seem to have WMI installed", , Title
  Call Cleanup
End If
On Error GoTo 0
For Each obj in oWMI.ExecQuery("Select * from Win32_OperatingSystem")
  Set oOS = obj
  Exit For
Next

WScript.Sleep SetTimer()

ShutDownNow

Function SetTimer()
  Dim MinSpec
  MinSpec = InputBox(ErrMsg & vbcrlf & "Enter number of minutes until " & _
                     "Shutdown.  You will have an option to cancel " & _
                     "shutdown for 1 minute before time elapses.",Title)
  If MinSpec = "" Then
    Cleanup
  ElseIf Not IsNumeric(MinSpec) Then
    ErrMsg = "Invalid Selection!" & vbcrlf & vbcrlf
    SetTimer()
  ElseIf MinSpec < 1 Then
    ErrMsg = "Invalid Selection!" & vbcrlf & vbcrlf
    SetTimer()
  Else
    If MinSpec > 1 Then
      SetTimer = (MinSpec - 1) * 1000 * 60
    Else
      SetTimer = MinSpec * 1000 * 60
    End If
  End If
End Function

Sub ShutDownNow()
  Const EWX_LOGOFF = 0
  Const EWX_SHUTDOWN = 1
  Const EWX_REBOOT = 2
  Const EWX_FORCE = 4
  Const EWX_POWEROFF = 8
  oOS.Win32shutdown EWX_SHUTDOWN '+ EWX_FORCE
End Sub

Sub Cleanup
  Set ws = Nothing
  WScript.Quit
End Sub
</script>

 

原帖:http://www.2yup.com/asp/forum/branch.asp?pid=115548

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:610678次
    • 积分:10491
    • 等级:
    • 排名:第1575名
    • 原创:408篇
    • 转载:108篇
    • 译文:0篇
    • 评论:50条
    最新评论
    我的师父