Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use vbs to implement a script that shuts down or restarts regularly

Shulou Source: shulou.com Published: 2022-06-03 06:44:01 09月16日 Update

This article mainly introduces how to use vbs to achieve a timing shutdown or restart script, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Dim ActionID

ActionID = 1'0 logout, 1 shutdown, 2 restart

ActionTime = "2006-1-4 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

'Please remove the comments on the following line when using it

'objShell.sendKeys ("{ENTER}")

End function

While true

If DateDiff ("s", Now, ActionTime) < 0 then

ShutDown ()

End if

WScript.Sleep (5x 1000)

Wend

'Save the above code as a vbs file, such as shutdown.vbs, and then double-click or right-click on the file to open it at the command prompt

If it's time for you to set up a restart, the system will display a shutdown dialog box.

'directly below the code program will appear the shutdown dialog box, and the final enter comment has been dropped. When in normal use, please remove the comment character.

Thank you for reading this article carefully. I hope the article "how to use vbs to achieve a scheduled shutdown or restart script" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles comments scripts code dialogs files conversations values interests at the same time commands time more friends knowledge programs systems editing industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Information MariaDB Microsoft Docker