How to implement computer shutdown or restart in VBScript

Source: Internet
Author: User
Tags implement domain registration
VBScript when we sometimes need to let the computer automatically restart or shutdown, often use some automatic shutdown software to achieve, but these software in addition to need to install, many still need to charge. And there is no shortage of successful operation after installation.
In fact, you do not have to pay to purchase any Third-party software to achieve automatic shutdown or restart, with a simple VBScript on it
Put the following code into the file Shutdown.vbs, and then in the directory where the file set up a shut.bat batch file, and finally set a task scheduled to run Shut.bat can be implemented at timed shutdown or restart the computer. That is simple and economical, why not try it?
------------------------------------------------
Content of Shut.bat:

cscript Shutdown.vbs

------------------------------------------------
The content of Shutdown.vbs

' Program design, Global worldwide
' http://www.netInter.cn, professional to provide domain registration, virtual host services
' The above information and the text of the article is an inseparable part, so if you want to reprint this article, you must retain the above information.

' Downflag is a shutdown sign
' downflag=12 indicates forced shutdown of the computer
' Downflag=8 shut down the computer
' downflag=6 indicates forced restart of computer
' downflag=2 means reboot the computer
' Downflag=4 indicates forced logoff
' Here we use 12 to force the computer to shut down
Downflag=12


Set Win32_os=getobject ("winmgmts:{(Shutdown)}//./root/cimv2"). ExecQuery ("select * from Win32_OperatingSystem where Primary=true ")
For each OS in Win32_os
Os.win32shutdown (Downflag)
Next
Set win32_os=nothing



Related Article

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.