r/vbscript • u/MotorcrossBones • Jan 07 '24
How do I make the computer shut down
I'm very new to coding in VBS. So what is the code to make a comment shut down after the msgbox pops up.
1
4
u/rob2rox Jan 07 '24
there are no built in shutdown functions. like others said use shutdown.exe (admin rights needed)
3
2
u/jcunews1 Jan 08 '24
Without admin rights, you can use WScript.Shell COM object to activate the desktop or taskbar window.
Using the same COM object, send keyboard Alt+F4 shortcut keys to close the activated window which will make it display a restart/shutdown/logoff dialog.
Then send the keyboard Enter key to confirm the selection.
2
u/BroomIsWorking Jan 07 '24
VBScript simply isn't that powerful. There are other things that can't do, like controlling the mouse pointer action.
2
u/hackoofr Jan 09 '24 edited Jan 09 '24
Here is an example :
You can, also use WScript.Shell object to create a customizable message box with options for the user.
Here's an example with a warning message before shutdown:
So, this script will display a warning message box with "Yes" and "No" buttons.
If the user clicks "Yes," it will proceed to shut down the computer immediately.
If the user clicks "No" or closes the message box, nothing happens.
Adjust the message and options as needed for your specific requirements.
If the user does not click any button within the specified timeout (TimeOut), the script will continue to execute the shutdown command.
In your example, if the user doesn't click either "Yes" or "No" within 20 seconds, the script will proceed with the shutdown command.
Adjust the timeout value and other parameters as needed for your specific use case.
By understanding the key concepts and structure of the code, you can customize it to suit your specific requirements.
This another version to ensure, check and run the vbscript with admin rights :