How to check whether secure boot is enabled using python in windows os

0

 

Secure Boot is a feature of the Unified Extensible Firmware Interface (UEFI) that is designed to help protect the system against malicious software. In Windows, you can use the Windows Management Instrumentation (WMI) API to check whether Secure Boot is enabled on the system. Here is an example Python script that uses the wmi module to query the WMI interface and check the SecureBootEnabled property:


import wmi

def is_secure_boot_enabled():
    # Connect to the WMI interface
    w = wmi.WMI()

    # Query the Win32_BIOS class for the SecureBootEnabled property
    result = w.query("SELECT SecureBootEnabled FROM Win32_BIOS")

    # Check the value of the SecureBootEnabled property
    if len(result) > 0 and result[0].SecureBootEnabled == True:
        return True
    else:
        return False

# Example usage
if is_secure_boot_enabled():
    print("Secure Boot is enabled.")
else:
    print("Secure Boot is not enabled.")



This script first connects to the WMI interface using the wmi.WMI() function. It then queries the Win32_BIOS class for the SecureBootEnabled property, which indicates whether Secure Boot is currently enabled. The script checks the value of this property and returns a boolean value indicating whether Secure Boot is enabled or not.

Note that this script requires the wmi module to be installed, which can be installed using pip by running the command pip install wmi. Additionally, the script must be run with administrative privileges in order to access the WMI interface.


Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !