Python/Python for Windows

[Python] winreg 모듈을 이용한 Windows 공유폴더 레지스트리 설정 점검

Pydole 2019. 8. 24. 11:14

 

파이썬 winreg 모듈을 이용한 PC 공유폴더 레지스트리 설정 점검

 

 

 

- PC : AutoShareWks

- Server : AutoShareServer

 

DOC : https://docs.python.org/3/library/winreg.html

 

winreg — Windows registry access — Python 3.7.4 documentation

winreg — Windows registry access These functions expose the Windows registry API to Python. Instead of using an integer as the registry handle, a handle object is used to ensure that the handles are closed correctly, even if the programmer neglects to expl

docs.python.org

 

 


 

 

import winreg

key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r'SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters', 0)
    # winreg.OpenKey(key, sub_key, reserved=0)

cnt = 0

while True:
    try:
        name, data , kind = winreg.EnumValue(key,cnt)  # 레지스트리 키 오픈 튜플로 반환. winreg.EnumValue(key, index)
        cnt += 1
        if name == 'AutoShareWks' and data == 0:
            print('기본공유 설정이 Disabled 되어 있습니다. [%s], [%d]'%(name, data))
            break

    except OSError:
        print('기본공유 설정을 찾을 수 없습니다.')
        exit(0)

winreg.CloseKey(key)
----------------------------------------------------------------------------------
기본공유 설정이 Disabled 되어 있습니다. [AutoShareWks], [0]