How to work with the registry from a limited account in windows xp
-
Right now I run the code with a administrator user and works just fine, but when I do it with a limited account user the first time works just fine but the second time gives me this error: ERROR_ALREADY_EXISTS = Cannot Create a file when that file already exists. This is what I'm doing: 1.- LogonUser; with the administrator account. 2.- ImpersonateLoggedOnUser 3.- RegOpenKeyEx Does anyone knows how to work this around? Any help is greatly apreciated. Thanks... JH
-
Right now I run the code with a administrator user and works just fine, but when I do it with a limited account user the first time works just fine but the second time gives me this error: ERROR_ALREADY_EXISTS = Cannot Create a file when that file already exists. This is what I'm doing: 1.- LogonUser; with the administrator account. 2.- ImpersonateLoggedOnUser 3.- RegOpenKeyEx Does anyone knows how to work this around? Any help is greatly apreciated. Thanks... JH
A normal user does not have authority to modify/add existing values in HKLM so if you are specifying KEY_READ | KEY_WRITE as 'samDesired' the RegOpenKeyEx will fail. If you are only going to read leave off the KEY_WRITE, but if you need to modify the value, put it somewhere other than HKLM. This is why most software has to be installed by someone with admin authority; most software installs write to HKLM.
-
A normal user does not have authority to modify/add existing values in HKLM so if you are specifying KEY_READ | KEY_WRITE as 'samDesired' the RegOpenKeyEx will fail. If you are only going to read leave off the KEY_WRITE, but if you need to modify the value, put it somewhere other than HKLM. This is why most software has to be installed by someone with admin authority; most software installs write to HKLM.
First of all, thanks...skornel. I understand your answer, however; I am trying to enable and disable the USB Ports (HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\USBSTOR), which is already by default. It's not something that I created my self. Is there a way to modify this key val when the program is running with a limited account?. Thanks. Regards, JH
-
First of all, thanks...skornel. I understand your answer, however; I am trying to enable and disable the USB Ports (HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\USBSTOR), which is already by default. It's not something that I created my self. Is there a way to modify this key val when the program is running with a limited account?. Thanks. Regards, JH
I don't know of any way to change any value in HKLM from a normal user account that does not have admin rights. The only thing I can think of would be for someone with admin rights, to change the permissions on the HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services to allow modify rights to a particular group and then be sure the user is in that group. That may work but I've not tried it. 'Permissions...' is in the right-button context menu in RegEdit.
-
A normal user does not have authority to modify/add existing values in HKLM so if you are specifying KEY_READ | KEY_WRITE as 'samDesired' the RegOpenKeyEx will fail. If you are only going to read leave off the KEY_WRITE, but if you need to modify the value, put it somewhere other than HKLM. This is why most software has to be installed by someone with admin authority; most software installs write to HKLM.
skornel wrote:
A normal user does not have authority to modify/add existing values in HKLM so if you are specifying KEY_READ | KEY_WRITE as 'samDesired' the RegOpenKeyEx will fail. If you are only going to read leave off the KEY_WRITE, but if you need to modify the value, put it somewhere other than HKLM.
True, but what does all of this have to do with
ERROR_ALREADY_EXISTS
?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
skornel wrote:
A normal user does not have authority to modify/add existing values in HKLM so if you are specifying KEY_READ | KEY_WRITE as 'samDesired' the RegOpenKeyEx will fail. If you are only going to read leave off the KEY_WRITE, but if you need to modify the value, put it somewhere other than HKLM.
True, but what does all of this have to do with
ERROR_ALREADY_EXISTS
?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
It is because, actually you change value in HKCU not in HKLM. You said, it works for first time and it fails for second time. Well, it works first because there is no key exist before and you have write access. So this is HKCU. It fails second because, you already wrote it when your first time. Probably you do not check result of ImpersonateLoggedOnUser function.
modified on Thursday, May 14, 2009 2:42 AM
-
It is because, actually you change value in HKCU not in HKLM. You said, it works for first time and it fails for second time. Well, it works first because there is no key exist before and you have write access. So this is HKCU. It fails second because, you already wrote it when your first time. Probably you do not check result of ImpersonateLoggedOnUser function.
modified on Thursday, May 14, 2009 2:42 AM
Perhaps you meant to reply to the OP, but after 2 years he may have moved on. :rolleyes:
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons