My code doesn't work as expected :
import subprocess
key = 'reg delete HKEY_USERS\S-1-5-21-2637495828-1099793317-3825703309-1000\SOFTWARE\Classes\CLSID\{0E270DAA-1BE6-48F2-AC49-D955BE4EEF1D} /f'
subprocess.call(key, shell=True)
Running Windows 10 64b, tried with subprocess.Popen aswell.
My first thought is I have to escape \ somehow, but I'm not sure if that's what I need, nor how to do it.
I also tried to make it work with a list of args key = ['reg', 'delete', 'HKEY...'])
, which gave the same result
Result from python script
C:\test.py
Error : Couldn't find the key or registry value
Result from the command from the Windows prompt
C:\reg delete HKEY_USERS\S-1-5-21-2637495828-1099793317-3825703309-1000\SOFTWARE\Classes\CLSID\{0E270DAA-1BE6-48F2-AC49-D955BE4EEF1D} /f
Operation Suceeded
N.B. I exported the key so I can add it again after every successful try.
N.B. Windows return messages were translated, and may not be accurate.
I thought so (the 32bit part). You're running into a problem generated by [MS>Docs]: Registry Keys Affected by WOW64.
In other words (on 64bit Win), for some registry keys (this one included), there are 2 separate locations:
- One for 64bit (default (and old) one)
- One for 32bit (brand new)
By default a 64bit app automatically uses the 64bit registry location; same thing for *32bit8 (of course that can be programmatically modified - at least for 64bit apps).
So, in order for 32bit apps that have some registry keys hardcoded, to still work on 64bit Win (remember the key hardcoded in the 32bit app is now 64bit, and it's invisible to the app, while the real 32bit is someplace else), MS came up with this approach. Same approach applies to paths on the filesystem (System32 vs SysWOW64 under C:\Windows).
Now why does it work from cmdline? Being a 64bit OS, the default cmd is 64bit (which launches the 64bit reg.exe), so it finds the key. Yes, you have 2 cmds (one under each of the above folders), actually (almost) all the Win executables (and .dlls) are "duplicated".
To test, start cmd.exe from C:\Windows\SysWOW64, and run the reg command and it will fail.
Finally, to get past this, associate .py files (I noticed that you ran it directly) with a 64bit Python version (you might have to download and install it).