A self-written vbs script for Timed Shutdown or restart

Source: Internet
Author: User


Dim actionid
Actionid = 1' 0 logout, 1 shutdown, 2 reboot,
Actiontime = "13:42:30" 'shutdown or restart time

Function Shutdown ()
Dim objshell
Set objshell = wscript. Createobject ("wscript. Shell ")

Dim Application
Set Application = Createobject ("shell. application.1 ")
Application. shutdownwindows ()
Dim upI
For UPI = 0 to 4
Wscript. Sleep (50)
Objshell. sendkeys ("{up }")
Next
For UPI = 1 to actionid
Wscript. Sleep (50)
Objshell. sendkeys ("{down }")
Next
'Remove the downstream annotator when using it.
'Objshell. sendkeys ("{enter }")
End Function

While true
If datediff ("S", now, actiontime) <0 then
Shutdown ()
End if
Wscript. Sleep (5*1000)
Wend

'Set the aboveCodeSave as a vbs file, such as shutdown. vbs. Double-click the file or right-click the file and choose to open it with a command prompt,
'If you set the restart, the system will shut down dialog box appears.
'Directly run the following code:ProgramThe shutdown dialog box appears, and the last carriage return is commented out. Remove the annotator during normal use.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.