468,291 Members | 1,655 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,291 developers. It's quick & easy.

How to disable/enable usb ports using python

Hey, Im new to python and trying to code a script which should enable/disable usb using winreg. Whats wrong in this code

code:

import winreg
def usbenordis(value):
try:
keyval=r"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlS et\Services\UsbStor"
if not os.path.exists("keyval"):
key = CreateKey(HKEY_CURRENT_USER,keyval)
Registrykey= OpenKey(HKEY_CURRENT_USER, r"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Serv ices\UsbStor", 0,KEY_WRITE)
if value == true:
SetValueEx(Registrykey,"start",0,REG_SZ,4)
print "usb disabled"
elif value == false:
SetValueEx(Registrykey,"start",0,REG_SZ,3)
print "usb enabled"
CloseKey(Registrykey)
return True
except WindowsError:
return False
def main():
x=usbenordis(true)
Jul 22 '18 #1
0 2346

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Alexander Vasilevsky | last post: by
10 posts views Thread by viki1967 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.