Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write in Python 2.7. Write a program that takes a value from a user and s

ID: 3848179 • Letter: P

Question

Please write in Python 2.7. Write a program that takes a value from a user and stores it in the registry. You can use any key name that you like but also store the current time as another value inside of your new key. Finally, get a directory listing of your current working directory and store that value. You may need to use REG_MULTI_SZ for that value. I'm having alot of trouble and would really appreciate some assistance.

(A solution other than the ones posted on Chegg would be greatly appreciated as the existing solutions posted don't work... Please try running the script before posting a solution to make sure it really works..)

Using Python 2 or 3, write a program that takes a value (input) from the user and stores it in the Windows registry. You can use any key name that you like but also store the current time as another value inside of your new key. Finally, get a directory listing of your current working directory and store that value. You may need to use REG_MULTI_SZ for that value.

I guess the main question is what's the solution code for this?

Please let me know what you don't understand.

Explanation / Answer

import _winreg
import datetime

def write_to_key(key, name, value):  
   """Writes some data to the given key if it is under HKEY_CURRENT_USER."""
   # OPEN
   reg_key_1 = _winreg.OpenKey(
       _winreg.HKEY_CURRENT_USER, key,
       0, _winreg.KEY_WRITE )
   # SET
   _winreg.SetValueEx(
       reg_key_1, name,
       0, _winreg.REG_SZ, value )
   # CLOSE
   _winreg.CloseKey(reg_key_1)

  

## ==== MAIN ====
_winreg.CreateKey(_winreg.HKEY_CURRENT_USER, "rj_key_1")

# USER INPUT
inp = raw_input("Just enter something and hit return!")
write_to_key("rj_key_1", "Some input from user", inp)

# TIME
now = str(datetime.datetime.now())
write_to_key("rj_key_1", "Time now", now)