import _winreg as wr
#找到Python.exe,单击右键,选安全选项框,在点以管理员权限运行
def HideDesk(disk):
i = ord(disk.upper()) - 65
hReg = wr.ConnectRegistry(None,wr.HKEY_CURRENT_USER)
try:
hKey= wr.OpenKey(hReg,r"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer",0,wr.KEY_ALL_ACCESS)
old,type = wr.QueryValueEx(hKey,'NoDrives')
new = old | 1<,'NoDrives',0,wr.REG_DWORD,new)
wr.CloseKey(hKey)#请把python.exe提升为管理员权限才能成功
except:
return 'No Right'
return 'success'
def main():
print HideDesk('D')#隐藏D盘
print HideDesk('E')
if __name=="__main__":
main()