주호의 공작소

파이썬3으로 작성한 윈도우 쓰기방지입니다.

관리자 권한이 필요하며, 옵션은 on, off, status가 있습니다. 예)python3 blocker.py on

설정 후 인식된 외부저장장치만 영향을 받으며, 소프트웨어 방식의 쓰기방지이므로 맹신해서는 안되겠습니다.

from winreg import *
import sys

reg_path = r"SYSTEM\CurrentControlSet\Control\StorageDevicePolicies"


def make_Write_handle():
    CreateKey(HKEY_LOCAL_MACHINE, reg_path)
    reg_handle = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
    return OpenKey(reg_handle, reg_path, 0, KEY_WRITE)


def make_Access_handle():
    CreateKey(HKEY_LOCAL_MACHINE, reg_path)
    reg_handle = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
    return OpenKey(reg_handle, reg_path, 0, KEY_ALL_ACCESS)


def set_value():
    key = make_Write_handle()
    try:
        SetValueEx(key, "WriteProtect", 0, REG_DWORD, 0x1)
        print("Successfully turned ON WriteBlock")
    except:
        print("Problem has occured..")
    CloseKey(key)


def reset_value():
    key = make_Write_handle()
    try:
        SetValueEx(key, "WriteProtect", 0, REG_DWORD, 0x0)
        print("Successfully turned OFF WriteBlock")
    except:
        print("Problem has occured..")
    CloseKey(key)


def find_value():
    key = make_Access_handle()
    try:
        value, _ = QueryValueEx(key, "WriteProtect")
        if value == 1:
            print("WriteBlock is ON")
        else:
            print("WriteBlock is OFF")
    except:
        print("Problem has occured..")
    CloseKey(key)


if len(sys.argv) != 2:
    print("Please select only one option.")
    print(r"EX) on, off, status")
    sys.exit()
param = sys.argv[1]
if param == "on":
    set_value()
if param == "off":
    reset_value()
if param == "status":
    find_value()
 

GitHub - Juuuho/Windows_WriteBlocker: Windows Registry based external storage write blocker

Windows Registry based external storage write blocker - GitHub - Juuuho/Windows_WriteBlocker: Windows Registry based external storage write blocker

github.com

 

profile

주호의 공작소

@Juho_H

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!