Created
November 9, 2017 21:43
-
-
Save sbraz/5dfe73fc1e342ba4b1cd4a6ef9bd8df2 to your computer and use it in GitHub Desktop.
A quick hack to temporarily change grub2's default entry from Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import subprocess | |
| import sys | |
| import ctypes | |
| import msvcrt | |
| import os | |
| import re | |
| def is_admin(): | |
| try: | |
| return ctypes.windll.shell32.IsUserAnAdmin() | |
| except: | |
| return False | |
| if __name__ == "__main__": | |
| params = subprocess.list2cmdline(sys.argv) | |
| try: | |
| if not ctypes.windll.shell32.IsUserAnAdmin(): | |
| raise Exception | |
| except: | |
| ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, params, None, 1) | |
| sys.exit(0) | |
| if not os.path.exists("B:/"): | |
| subprocess.run(["mountvol", "B:", "/s"]) | |
| buf = b"# GRUB Environment Block\n" | |
| buf += b"next_entry=0\n" | |
| buf += b"#" * (1024 - len(buf)) | |
| with open("B:/grub/grubenv", "wb") as f: | |
| f.write(buf) | |
| print("Press return to reboot, any other key to continue") | |
| choice = msvcrt.getch() | |
| if choice == b"\r": | |
| subprocess.call(["shutdown", "/r", "/t", "0"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment