Skip to content

Instantly share code, notes, and snippets.

@gkeep
Last active May 12, 2021 21:25
Show Gist options
  • Save gkeep/7fd461c88f4eb1deeb91e62cfea27685 to your computer and use it in GitHub Desktop.
Save gkeep/7fd461c88f4eb1deeb91e62cfea27685 to your computer and use it in GitHub Desktop.
Script to toggle Hyper-V
pyinstaller --noconfirm --log-level=WARN ^
--clean --onefile --uac-admin ^
main.spec
copy dist\main.exe toggle_hyperv.exe
import subprocess
import elevate
def main():
action = None
action = int(input("> "))
if action == 0:
try:
subprocess.run(
"bcdedit /set hypervisorlaunchtype off", check=True, shell=True
)
except:
print("Couldn't disable Hyper-V")
elif action == 1:
try:
subprocess.run(
"bcdedit /set hypervisorlaunchtype auto", check=True, shell=True
)
except:
print("Couldn't enable Hyper-V")
else:
print("Unknown action {}, please try again".format(action))
main()
inp = input("Do you want to reboot? (0 - no, 1 - yes)\n> ")
reboot = True if inp.lower() in ["1", "true", "t"] else False
if reboot:
print("Rebooting in 3 seconds...")
subprocess.run("shutdown /r /t3")
input()
if __name__ == "__main__":
elevate.elevate()
print("0 - Disable Hyper-V\n1 - Enable Hyper-V")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment