By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,650 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,650 IT Pros & Developers. It's quick & easy.

How to disable/enable usb ports using python

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


import winreg
def usbenordis(value):
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:
print "usb disabled"
elif value == false:
print "usb enabled"
return True
except WindowsError:
return False
def main():
Jul 22 '18 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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