hide_or_unhide = 1
"""
give 1 if you want to hide the shutdown option from the start menu
give 0 if you want to unhide the shutdown option back to the start menu
"""

import os
from subprocess import PIPE, Popen
import ctypes

class disable_file_system_redirection:
    _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
    _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
    def __enter__(self):
        self.old_value = ctypes.c_long()
        self.success = self._disable(ctypes.byref(self.old_value))
    def __exit__(self, type, value, traceback):
        if self.success:
            self._revert(self.old_value)

def ecmd(command):   
    from subprocess import Popen, PIPE
    import ctypes
    
    with disable_file_system_redirection():
        obj = Popen(command, shell = True, stdout = PIPE, stderr = PIPE)
    out, err = obj.communicate()
    ret=obj.returncode
    return ret,out,err
            
if hide_or_unhide==0:
    ret,out,err = ecmd(r'reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PolicyManager\default\Start\HideShutDown" /v value /t REG_DWORD /d 0 /f')
    if ret==0:
        if out:
            print(out)
        print('successfully added the shutdown option back to the start menu')
        
    else:
        print(err)
elif hide_or_unhide==1:
    ret,out,err = ecmd(r'reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PolicyManager\default\Start\HideShutDown" /v value /t REG_DWORD /d 1 /f')
    if ret==0:
        if out:
            print(out)
        print('successfully removed the shutdown option from the start menu')
    else:
        print(err)