Click here to Skip to main content
13,139,132 members (62,974 online)
Rate this:
Please Sign up or sign in to 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(
,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 24-Jan-13 7:59am
Updated 24-Jan-13 8:48am
Sergey Alexandrovich Kryukov 24-Jan-13 14:23pm
Did you check up the result of you writing using Regedit or something like that?
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"?
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

it's a security thing, take a look at this article and you should have your answer:[^]
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...
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, _

f.AddPathList( _
RegistryPermissionAccess.Write Or RegistryPermissionAccess.Read, _

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....
Adam R Harris 25-Jan-13 12:20pm
user322012 27-Jan-13 12:36pm
i read it but still can't access key to write it..

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100