No video

Updating the windows registry with python (Modify path variable in windows with python)

  Рет қаралды 9,718

Canadian Coding

Canadian Coding

Күн бұрын

Пікірлер: 17
@lily38942
@lily38942 3 жыл бұрын
underrated channel!
@nothkphh
@nothkphh 2 жыл бұрын
Thanks a lot!!! I trying to learn how to read WinRegistry, only your one video helps me. < 3
@ezzeldin101
@ezzeldin101 2 жыл бұрын
This is an awesome tutorial, Please keep it on!!
@samkani1277
@samkani1277 3 жыл бұрын
Thanks. The video was helpful😃😃
@josales3570
@josales3570 2 жыл бұрын
Ty for your video. Helped me a lot.
@__Paul__
@__Paul__ 3 жыл бұрын
This is all great, as long as you only want to write to the HKCU Registry hive. If you need to write keys and values to HKLM hive, then you either have to use a completely different language other than Python, or you have to use some other API other than "winreg", as winreg has a major defect that severely limits what you can do in the Registry, that most other languages have no problem with.
@canadiancoding
@canadiancoding 3 жыл бұрын
Interesting, my work with the registry is relatively limited. So does python just fail to make the changes to the HKLM key outright, or are they just non-persistent?
@__Paul__
@__Paul__ 3 жыл бұрын
@@canadiancoding It just fails to make them. It also throws a WinError 5, "access denied", but that is misleading and will only lead you down a dark alley. You can even configure your account not only as local admin, but full-on "god mode", elevating your account further to system level access, run as part of the operating system, etc., and still no love. IF it is "permissions", then it is solely in the calls internally to winreg, and / or security flag options that must be passed in -- NOT your actual account permissions or any special environment configuration settings. However, I have tried every combination (winreg.REG_WRITE / winreg.WIN_ALL_ACCESS / winreg.WIN64, etc), but nothing works when pointed to HKLM hive. Writing to HKCU is just fine. Meanwhile, I can manually modify Registy settings in HKLM, or do it with C# and .NET Framework classes, OR C# with dark, unmanaged C# with direct access to Win32 (advapi32.dll), no problem.
@canadiancoding
@canadiancoding 3 жыл бұрын
@@__Paul__ Thanks for letting me know, that's good for future reference. I guess Microsoft just happens to be more friendly with their own languages :)
@danielfridman8317
@danielfridman8317 3 жыл бұрын
Hi. Very helpful video!! Question: Is the - Tell other processes to update their environment - is completely necessary? What might happen if I won't do that? Thanks!
@canadiancoding
@canadiancoding 3 жыл бұрын
If you opt not to include the other part of the code the registry can become out of sync. What happens is the same thing that happens if a database is out of sync, sometimes you will get the updated value and sometimes you will get the old one.
@simonvonkleist6590
@simonvonkleist6590 3 жыл бұрын
Is that sublime as an editor or another one? Is there anything to be set up additionally to have the context information displayed?
@canadiancoding
@canadiancoding 3 жыл бұрын
This is visual studio code, and to get the intelisense to show up you would need to install the pylance extension
@markanthadon
@markanthadon 2 жыл бұрын
Any updates on mentioned issues with writing to HKLM using winreg?
@canadiancoding
@canadiancoding 2 жыл бұрын
Unfortunately not, I have not modified any of this code for a long time after searching for more information for a while
@LorhanSohaky
@LorhanSohaky Жыл бұрын
What is the reserved parameter? I'm noob with the winreg
@canadiancoding
@canadiancoding Жыл бұрын
I did quite a lot of digging, and found something that *might* be true about this. To understand this you need to know a few things Python in general is written in C/C++, in C/C++ header files (.h files) are used to tell you about functions. There are a few common windows ones like windows.h. Looking into the source code for winreg it seems to be using windows.h, but it seems to also be using a function defined in another .h file called RegOpenKeyExW() (learn.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regopenkeyexw), I do not know enough about the intricacies of C/C++ or windows to be able to confirm this, but it seems like this is what's being called by python (python actually runs C code and passes your variables to the C code under the hood) In the python source code only 1 place specifies the value can be something non-zero: github.com/python/cpython/blob/main/PC/winreg.c#L1731-L1771 and this is because it's replaced by a zero here github.com/python/cpython/blob/main/PC/winreg.c#L1793 Reading the documentation for RegOpenKeyExW() here: learn.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regopenkeyexw#:~:text=%5Bin%5D%20ulOptions,when%20absolutely%20necessary. It states that the value being passed as "reserved" is 0 for a regular link or set to the constant REG_OPTION_OPEN_LINK to make it a symbolic link. (with the warning "Registry symbolic links should only be used when absolutely necessary"). I am not as familiar with the registry, but a symbolic link in general is basically a "file" or "file-like" object that points to another (like a shortcut). It seems like this is the only other possible value, but they don't want you to do this in python (or C) because I would assume like normal symbolic links if the thing you're linking to is deleted, everything linking to it breaks as well! I apologize I couldn't be more precise in my response. As I said this is largely speculative, and my best guess. I would not act on this information until there is something more obvious to confirm this info, but I suspect this is what's happening. For time being, listen to the comments and leave it on 0
Windows Registry in Python
8:33
NeuralNine
Рет қаралды 10 М.
Hide Information in JPEG Files
16:19
NeuralNine
Рет қаралды 178 М.
Joker can't swim!#joker #shorts
00:46
Untitled Joker
Рет қаралды 39 МЛН
I'm Excited To see If Kelly Can Meet This Challenge!
00:16
Mini Katana
Рет қаралды 35 МЛН
ОБЯЗАТЕЛЬНО СОВЕРШАЙТЕ ДОБРО!❤❤❤
00:45
The Fastest Way to Loop in Python - An Unfortunate Truth
8:06
mCoding
Рет қаралды 1,4 МЛН
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 263 М.
I run untested, viewer-submitted code on my 500-LED christmas tree.
45:17
Don't Buy Audiobooks! 😎 Build Your Own With Just 12 Lines Of Python
13:04
An Introduction to Software Design - With Python
34:05
Tech With Tim
Рет қаралды 515 М.
How This New Battery is Changing the Game
12:07
Undecided with Matt Ferrell
Рет қаралды 158 М.
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 353 М.
Practical Windows Registry Explanation
3:26
Canadian Coding
Рет қаралды 1,3 М.
Joker can't swim!#joker #shorts
00:46
Untitled Joker
Рет қаралды 39 МЛН