Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
hello everyone

i am trying to write to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bmp\UserChoice in windows 7 and in that wanted to change progid through code(vb.net)
,i am able to read this key but when i am writing to this key its creating an error:
securityexception was unhandled,Requested registry access is not allowed.
Any help regarding the same would be help full.i tried to find solutions on internet but no help..
thanks in advance :)
here is my code

My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bmp\UserChoice", "Progid", "PBrush")
Posted
Updated 24-Jan-13 8:48am
v4
Comments
Sergey Alexandrovich Kryukov 24-Jan-13 14:23pm    
Did you check up the result of you writing using Regedit or something like that?
—SA
user322012 24-Jan-13 14:49pm    
i am not able to write it says access to registry key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bmp\UserChoice is denied
Sergey Alexandrovich Kryukov 24-Jan-13 14:53pm    
Did you run the code "as administrator"?
—SA
user322012 24-Jan-13 15:02pm    
yes i tried it but same error occurring ...
user322012 24-Jan-13 15:06pm    
when i am writing manually HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bmp\UserChoice key progid in regedit it says progid value can't be edited ..

1 solution

it's a security thing, take a look at this article and you should have your answer: http://msdn.microsoft.com/en-us/library/system.security.permissions.registrypermission(v=vs.90).aspx[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Jan-13 14:54pm    
Agree, my 5. But whatever it is, the solution should require OP to run as administrator anyway...
—SA
Adam R Harris 24-Jan-13 15:02pm    
Thank you kind sir
user322012 25-Jan-13 0:08am    
My code is:
Dim f As New RegistryPermission( _
RegistryPermissionAccess.Read, _
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bmp\UserChoice\0")

f.AddPathList( _
RegistryPermissionAccess.Write Or RegistryPermissionAccess.Read, _
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bmp\UserChoice\0")

My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bmp\UserChoice\0", "Progid", "Applications\notepad.exe")

This code creates a new key named "0" and writes value as "Applications\notepad.exe", but it doesnot change the default application set for any .bmp file to open(in my case its Ms Paint).

What i want is to change the default application to open a .bmp file through my code. if the default application is MS Paint, then I want it to change to Notepad, but through code only.
Adam R Harris 25-Jan-13 11:36am    
Try restarting, the registry is stored in memory and any changes to it wont take effect until the system reboots ... or you could try killing explorer.exe in the task manager, sometimes that works and sometimes it doesn't.

If that doesn't work use the search feature here, i know there are a few articles written on file associations.
user322012 25-Jan-13 12:08pm    
i am searching here but couldn't find any useful articles if you know any
give me links....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900