Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RegCreateKeyTransacted.py 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import win32api
  2. import win32con
  3. import win32transaction
  4. keyname = "Pywin32 test transacted registry functions"
  5. subkeyname = "test transacted subkey"
  6. classname = "Transacted Class"
  7. trans = win32transaction.CreateTransaction(Description="test RegCreateKeyTransacted")
  8. key, disp = win32api.RegCreateKeyEx(
  9. win32con.HKEY_CURRENT_USER,
  10. keyname,
  11. samDesired=win32con.KEY_ALL_ACCESS,
  12. Class=classname,
  13. )
  14. ## clean up any existing keys
  15. for subk in win32api.RegEnumKeyExW(key):
  16. win32api.RegDeleteKey(key, subk[0])
  17. ## reopen key in transacted mode
  18. transacted_key = win32api.RegOpenKeyTransacted(
  19. Key=win32con.HKEY_CURRENT_USER,
  20. SubKey=keyname,
  21. Transaction=trans,
  22. samDesired=win32con.KEY_ALL_ACCESS,
  23. )
  24. subkey, disp = win32api.RegCreateKeyEx(
  25. transacted_key,
  26. subkeyname,
  27. Transaction=trans,
  28. samDesired=win32con.KEY_ALL_ACCESS,
  29. Class=classname,
  30. )
  31. ## Newly created key should not be visible from non-transacted handle
  32. subkeys = [s[0] for s in win32api.RegEnumKeyExW(key)]
  33. assert subkeyname not in subkeys
  34. transacted_subkeys = [s[0] for s in win32api.RegEnumKeyExW(transacted_key)]
  35. assert subkeyname in transacted_subkeys
  36. ## Key should be visible to non-transacted handle after commit
  37. win32transaction.CommitTransaction(trans)
  38. subkeys = [s[0] for s in win32api.RegEnumKeyExW(key)]
  39. assert subkeyname in subkeys
  40. ## test transacted delete
  41. del_trans = win32transaction.CreateTransaction(
  42. Description="test RegDeleteKeyTransacted"
  43. )
  44. win32api.RegDeleteKeyEx(key, subkeyname, Transaction=del_trans)
  45. ## subkey should still show up for non-transacted handle
  46. subkeys = [s[0] for s in win32api.RegEnumKeyExW(key)]
  47. assert subkeyname in subkeys
  48. ## ... and should be gone after commit
  49. win32transaction.CommitTransaction(del_trans)
  50. subkeys = [s[0] for s in win32api.RegEnumKeyExW(key)]
  51. assert subkeyname not in subkeys
  52. win32api.RegDeleteKey(win32con.HKEY_CURRENT_USER, keyname)