Python Forum
Testing If a string has anything in it
Thread Rating:
  • 4 Vote(s) - 3.25 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Testing If a string has anything in it
#1
Guys,

In the code below I am going into the registry to look for a certain item. In this case I am using (RtkAudioService). Once it finds it will give the location of it. ("C:\Program Files\Realtek\Audio\HDA\RtkAudioService64.exe") Now when someone enters something else in the input that is not located in this location I want it to come up and state something that this is not located here or something along that line. All I am getting is the following Error bellow. How would you guys approach this?

What Program would you like to search for? f
Error:
Traceback (most recent call last): File "C:\Python27\SearchPath.py", line 29, in <module> print getMDACversion() File "C:\Python27\SearchPath.py", line 15, in getMDACversion hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, RegLocation) WindowsError: [Error 2] The system cannot find the file specified
import _winreg
from _winreg import *

usr_input = raw_input('What Program would you like to search for? ')
location = 'SYSTEM\\ControlSet001\\services\\'
RegLocation = location + usr_input

def getMDACversion():
hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, RegLocation)
result = _winreg.QueryValueEx(hKey, "ImagePath")
return result[0]

print getMDACversion()
Reply


Messages In This Thread
Testing If a string has anything in it - by elliep - Jul-28-2017, 02:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  testing if a character in a string is an intended one Skaperen 2 2,690 Feb-27-2018, 02:51 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020