473,320 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 4336

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

Similar topics

7
by: Michael | last post by:
I'm exploring how to programmatically disable/enable devices in a system using C#. -MH
4
by: Phoe6 | last post by:
Hi all, I am trying to disable the NIC card (and other cards) enabled in my machine to test diagnostics on that card. I am trying to disable it programmatic using python. I checked python wmi and...
1
by: vinesh kumar | last post by:
please guide me to access the usb ports using C together with the source code ....
3
by: Pietro | last post by:
Hi all, First of all I'd like to thank you very very much ,as finally after many years of searching,I could find a code to disable/enable the shift key,but actually i cannot use the code as I'm...
0
by: Alexander Vasilevsky | last post by:
Can to disable/enable smoothing font in the WPF? http://www.alvas.net - Audio tools for C# and VB.Net developers
10
by: viki1967 | last post by:
Disable/enable icon.gif Hi all. I have this form in the page.htm: <form action="form.asp" method="post" onsubmit="return(validateForm(this));"> <select size="1" name="t_im"...
10
by: sowmyati | last post by:
HI All, I am new to javascript. I have snippet wherein i am giving a brief note on what i am trying to do. In the below have a variable by name stuff. trying to reset the page. Part of the code...
1
AR Ratheesh
by: AR Ratheesh | last post by:
Hi, Please help me to disable / enable task manager and Explore for a internet Cafe management project. Thanks in advance..
0
by: Sajeev George | last post by:
I found the article for "Enable And Disable Network Adapter Using Shell32.Dll" But its not working in Windows 7. This works fine Windows Xp. The problem is happening is not Finding "Network...
0
by: hoadiem | last post by:
Hi, everyone I'm doing an excel add-ins , and let say i have a button in the ribbon. then i add a form to project , i have a button on the form . i want to click on this button to either disable /...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.