'************************************** ' Name: Windows 10 LogOff Shutdown ReBoo ' t PowerOff ' Description:A basic and straight-forwa ' rd Script to offer the choices LogOff Sh ' utdown ReBoot PowerOff to the user and t ' hen act on those choices. ' By: A_X_O ' ' ' Inputs:None ' ' Returns:None ' 'Assumes:None ' 'Side Effects:None '************************************** ' '--------------------------------------- ' ---------------------------------------- ' '+++++++++++++++++++++++++++++++++++++++ ' ++++++++++++++++++++++++++++++++++++++++ ' ' Demonstration: Windows 10, LogOff Shu ' tdown ReBoot PowerOff ' '+++++++++++++++++++++++++++++++++++++++ ' ++++++++++++++++++++++++++++++++++++++++ ' ' ' ' Purpose : Demonstrates Operating Syst ' em Management ' ' -------------------------------------- ' --------------------------------- ' ' Creation Date : 27/03/2019 [dd/mm/yyyy ' ] ' ' Version : 1:1 ' ' Designer : Fabian ' ' ' '####################################### ' ######################################## ' ' MODIFICATION HISTORY ' '--------------------------------------- ' ---------------------------------------- ' ' ' ' Version : 1:0 27/03/2019 Create the S ' ample ' ' : 1:1 27/03/2019 Fix minor comment e ' rrors ' ' : 1:1 27/03/2019 Add Escape options ' for user ' ' ' '--------------------------------------- ' ---------------------------------------- ' ' Call SubMain() ' Public Const EWX_LOGOFF = 0 Public Const EWX_SHUTDOWN = 1 Public Const EWX_REBOOT = 2 Public Const EWX_POWEROFF = 8 ' Public TOKEN ' Public Const StrQuestionText = "Enter the appropriate number for the task you would like performed." Public Const StrQuestionErr = "Only numbers from 1 - 4 can be used." Public Const StrQuestionRetry = "Would you like to try again ?" Public Const StrQuestionTitle = "Select an Option." Public Const StrQuestionInTitle = "LogOff Shutdown PowerOff ReBoot ?" Public Const StrQuestionDefaultVal = "2" ' Public Const StrLOGOFF = "Enter: 1 to Log-Off" '<-- 0 is the Actual Constant Public Const StrSHUTDOWN = "Enter: 2 to Shutdown" '<-- 1 is the Actual Constant Public Const StrREBOOT = "Enter: 3 to Re-Boot" '<-- 2 is the Actual Constant Public Const StrPOWEROFF = "Enter: 4 to Power-Off" '<-- 8 is the Actual Constant ' Public Const StrConfirm = "Are you sure you want to take this action ?" Public Const StrConfirmTitle = "Windows Session" ' Dim objWMIService Dim colItems Dim objItem ' Dim Question Dim QuestionSelect Dim RetVal ' Public Sub SubMain() On Error Resume Next ' Set objWMIService = GetObject("winmgmts:{(Shutdown)}\\.\root\CIMV2") ' Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem Where Primary=True") ' QuestionSelect = VbCrLf & VbCrLf & StrLOGOFF & VbCrLf & StrSHUTDOWN & VbCrLf & StrREBOOT & VbCrLf & StrPOWEROFF & VbCrLf Question = InputBox(((StrQuestionText) & (QuestionSelect)),(StrQuestionInTitle),StrQuestionDefaultVal) ' Rem: Handle the Cancel option in the Inp ' ut ' If Question = VbNullString Then: Wscript.Quit ' Rem: Briefly check to make sure the ente ' red data is what we expect, ie, integers ' from 1 to 4 ' If Not IsNumeric(Question) Or Question > 4 Or Question < 1 Then ' RetVal = MsgBox((StrQuestionErr) & VbCrLf & (StrQuestionRetry),VbSystemModal + VbExclamation + vbRetryCancel,(StrQuestionTitle)) ' Select Case RetVal ' Case VbRetry ' Call SubMain() ' Case VbCancel ' WScript.Quit ' End Select ' Else ' Call SystemManagement(Question) ' End If ' End Sub ' Public Sub SystemManagement(ByVal IntAction) On Error Resume Next ' Rem: Added Escape Option ' Dim ConfirmQuestion ' ConfirmQuestion = Msgbox((StrConfirm), VbSystemModal + VbExclamation + VbYesNo, (StrConfirmTitle)) ' Select Case ConfirmQuestion ' Case VbYes ' If IntAction = 1 Then ' TOKEN = EWX_LOGOFF ' ElseIf IntAction = 2 Then ' TOKEN = EWX_SHUTDOWN ' ElseIf IntAction = 3 Then ' TOKEN = EWX_REBOOT ' ElseIf IntAction = 4 Then ' TOKEN = EWX_POWEROFF ' End If ' For Each objItem in colItems ' objItem.Win32Shutdown TOKEN ' Next ' Case VbNo ' Set objWMIService = Nothing Set colItems = Nothing ' WScript.Quit ' End Select ' End Sub ' '