RegOpenKeyEx gets error 5 (ERROR_ACCESS_DENIED)
-
I am trying to access this key in my code (which is a Windows Service and is launched with admin privilege):
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture
and I keep getting the error code 5 (ERROR_ACCESS_DENIED
). I followed this solution[^] to adjust the token privilege. This step succeeded, but thenRegOpenKeyEx
still returnedERROR_ACCESS_DENIED
. What else should I do to access this key? Thanks in advance.Maxwell Chen
-
I am trying to access this key in my code (which is a Windows Service and is launched with admin privilege):
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture
and I keep getting the error code 5 (ERROR_ACCESS_DENIED
). I followed this solution[^] to adjust the token privilege. This step succeeded, but thenRegOpenKeyEx
still returnedERROR_ACCESS_DENIED
. What else should I do to access this key? Thanks in advance.Maxwell Chen
-
I am trying to access this key in my code (which is a Windows Service and is launched with admin privilege):
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture
and I keep getting the error code 5 (ERROR_ACCESS_DENIED
). I followed this solution[^] to adjust the token privilege. This step succeeded, but thenRegOpenKeyEx
still returnedERROR_ACCESS_DENIED
. What else should I do to access this key? Thanks in advance.Maxwell Chen
Hi Maxwell, Its not an answer but I have one doubt. Are you sure that your application is launched with admin priviledge ?? I am also doing the same in Windows Service and it is working fine in XP, Windows 7 and Vista. If my application is not lauched with admin priviledge than i get access denied error else it is working fine.
I believe in LOVE AT FIRST SIGHT... Bcoz I have loved my Mother... even since I opened my eyes...(ICAN)
-
Are you on Windows-7? then see this thread.. http://social.msdn.microsoft.com/Forums/en/windowscompatibility/thread/073349b1-0f29-41ef-aaab-dbb262d52457[^]
Hi Cool_Dev, I roughly had a glance on the discussion thread just now. In the thread, they came out with the solution using manifest file, right? Answering to your question: Yes, I am on Windows 7 32-bit platform. My code is to be compiled with VC++6 and WDK 6000. So manifest files might not be the solution to this issue ... I guess.
Maxwell Chen
-
Hi Maxwell, Its not an answer but I have one doubt. Are you sure that your application is launched with admin priviledge ?? I am also doing the same in Windows Service and it is working fine in XP, Windows 7 and Vista. If my application is not lauched with admin priviledge than i get access denied error else it is working fine.
I believe in LOVE AT FIRST SIGHT... Bcoz I have loved my Mother... even since I opened my eyes...(ICAN)
Hi Shilpi,
Shilpi Boosar wrote:
Are you sure that your application is launched with admin priviledge ??
I think so. I right-click on the Command Prompt shortcut, and choose "Run as Admin", to open a DOS-box. And then I type the command:
MyService.exe -r
to setup and start the service.Maxwell Chen
-
Hi Cool_Dev, I roughly had a glance on the discussion thread just now. In the thread, they came out with the solution using manifest file, right? Answering to your question: Yes, I am on Windows 7 32-bit platform. My code is to be compiled with VC++6 and WDK 6000. So manifest files might not be the solution to this issue ... I guess.
Maxwell Chen
-
Hi Shilpi,
Shilpi Boosar wrote:
Are you sure that your application is launched with admin priviledge ??
I think so. I right-click on the Command Prompt shortcut, and choose "Run as Admin", to open a DOS-box. And then I type the command:
MyService.exe -r
to setup and start the service.Maxwell Chen
I don't think that means the service will run as admin, though. When the service is installed, it determines what user it will run as. Open Task Manager, find the process that represents your service and check what user account it is running under.
The difficult we do right away... ...the impossible takes slightly longer.
-
I don't think that means the service will run as admin, though. When the service is installed, it determines what user it will run as. Open Task Manager, find the process that represents your service and check what user account it is running under.
The difficult we do right away... ...the impossible takes slightly longer.
Richard Andrew x64 wrote:
Open Task Manager, find the process that represents your service and check what user account it is running under.
Hi Richard, My service is running under the name
SYSTEM
. (The logon session user account is "user
".)Maxwell Chen
-
That thread says that the error code 5 can be ERROR_CANTWRITE also. Have a look into it. you can ensure it by checking the value got in in PHKEY argument. Also try using KEY_ALL_ACCESS Or KEY_WOW64_64KEY in RegOpenKeyEx.
Cool_Dev wrote:
That thread says that the error code 5 can be ERROR_CANTWRITE also. Have a look into it. you can ensure it by checking the value got in in PHKEY argument. Also try using KEY_ALL_ACCESS Or KEY_WOW64_64KEY in RegOpenKeyEx.
Hi Cool_Dev, 1) The name
KEY_WOW64_64KEY
is not defined in VC++ 6. So I did not add it since the compiler said "undeclared identifier". 2)RegOpenKeyEx
returns value0
in thePHKEY
argument. 3) I have been usingKEY_ALL_ACCESS
all the time. 4) During run-time seen on the debugger,ERROR_ACCESS_DENIED
is0x0005
andERROR_CANTWRITE
is0x03F5
. Please refer to the screenshot[^] on VC++2005 remote debugger.Maxwell Chen
-
I don't think that means the service will run as admin, though. When the service is installed, it determines what user it will run as. Open Task Manager, find the process that represents your service and check what user account it is running under.
The difficult we do right away... ...the impossible takes slightly longer.