Click here to Skip to main content
Rate this: bad
good
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(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 Smile | :)
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
Edited 24-Jan-13 8:48am
v4
Comments
Sergey Alexandrovich Kryukov at 24-Jan-13 14:23pm
   
Did you check up the result of you writing using Regedit or something like that?
—SA
user322012 at 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 at 24-Jan-13 14:53pm
   
Did you run the code "as administrator"?
—SA
user322012 at 24-Jan-13 15:02pm
   
yes i tried it but same error occurring ...
user322012 at 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
good
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: http://msdn.microsoft.com/en-us/library/system.security.permissions.registrypermission(v=vs.90).aspx[^]
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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 at 24-Jan-13 15:02pm
   
Thank you kind sir
user322012 at 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 at 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 at 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 at 25-Jan-13 12:20pm
   
user322012 at 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
0 OriginalGriff 430
1 DamithSL 288
2 Sergey Alexandrovich Kryukov 220
3 Peter Leow 215
4 Maciej Los 195


Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid