When I try to modify HKEY_CLASSES_ROOT with my program in Windows Vista to assign file types to my program, I get permission denied.
Printable View
When I try to modify HKEY_CLASSES_ROOT with my program in Windows Vista to assign file types to my program, I get permission denied.
Is it safe to assume that you are the administrator?
Yes, I am an administrator. Want the code?
Here you go.
vb Code:
Public Sub AssociateFile(ByVal FileType As String, Optional ByVal Extra As String = " -unknownfile", Optional ByVal TitleInContext As String = vbNullString, Optional ByVal CommandInContext As String = vbNullString, Optional ByVal CommandReferenceContext As String = vbNullString) My.Computer.Registry.ClassesRoot.CreateSubKey(FileType).SetValue(vbNullString, FileType, Microsoft.Win32.RegistryValueKind.String) My.Computer.Registry.ClassesRoot.CreateSubKey(FileType & "\shell\open\command").SetValue(vbNullString, Application.ExecutablePath & Extra & " vbNullString%lvbNullString ", Microsoft.Win32.RegistryValueKind.String) If Not TitleInContext = vbNullString Then Dim RegK As Microsoft.Win32.RegistryKey Dim RegSK As Microsoft.Win32.RegistryKey RegK = My.Computer.Registry.ClassesRoot.OpenSubKey(FileType, False).OpenSubKey("shell", True) RegSK = RegK.CreateSubKey(CommandReferenceContext) RegSK.SetValue(vbNullString, TitleInContext) RegSK.CreateSubKey("command").SetValue(vbNullString, CommandInContext) End If End Sub
Areas of the registry are protected from access. The HKCU is about the only allowable area to read/write, even as administrator.
You need to add trust to your app or add some security allowences.
OK. How do I do that then? Can anyone be extremely nice and tell me? I have a deadline in 7 days.
You need to elevate the process and run it as an Administrator.
One of the easiest but not the best way is to set your manifest file to require administrator level or just right click on the compiled exe and set it to run as Administrator.
How do I modify the manifest file?Quote:
Originally Posted by RobDog888
Do a Forums search.
Didn't find anything. Searched for both "Manifest" and "Vista manifest" and looked ALL posts through. Nothing to suit my needs. Even though I only searched in this forum. Should I search everywhere?
First hit on my search of the forums.
http://www.vbforums.com/showthread.php?t=482140
Its more explained better on the microsoft site but for the short and simple it works.