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

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
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.