Click here to Skip to main content
15,921,062 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am try yo make my application autostart when windows start. It works fine on windows XP but gives me error "Attempt to perform an unauthorized operation" on Windows 7 Professional 64B, Window Vista Ultimate 32B and Window Vista Business 32B

I am using below code:

VB
Try
      Dim regKey As RegistryKey
      regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)

      If MyAppsCheckBox.Checked = true Then
        regKey.SetValue("MyApp", Application.ExecutablePath.ToString())
      Else
        regKey.DeleteValue("MyApp", True)
      End If
      regKey.Close()
    Catch ex As Exception
      msgbox(ex.Message)
    End Try


I am unable to find the solution for above problem.
Please help
Posted

1 solution

Windows 7 uses User Account Control and will not allow you to write to the registry unless you run the program as an administrator.

The other option you have is to use an 'Elevated' manifest file - read more about this approach here[^].
 
Share this answer
 
Comments
Wendelius 19-Dec-11 0:36am    
5'd. Also, good link
Abhinav S 19-Dec-11 0:40am    
Thank you Mika.
kals84 19-Dec-11 0:42am    
I am logged in with administrator and my program is running under administrator privilege.

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