Results 1 to 8 of 8

Thread: Edit Registry Keys

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    27

    Edit Registry Keys

    Hey guys,

    I'm looking to enable and/or disable a proxy by button in a program. I have looked at the msdn examples but can't figure out how to navigate to:

    hkey_current_user\Software\microsoft\windows\currentversion\internet settings

    This is my current code:

    Code:
    Imports Microsoft.VisualBasic
    Imports System
    Imports System.Security.Permissions
    Imports Microsoft.Win32
    <Assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, ViewAndModify:="HKEY_CURRENT_USER\Microsoft\Windows\CurrentVersion\Internet Settings")> 
    Public Class Form1
        Dim Test As RegistryKey
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            'Test.OpenSubKey("Test")
            'Test.OpenSubKey("Windows")
            'Test.OpenSubKey("CurrentVersion")
            'Test.OpenSubKey("Internet Settings")
            Test.SetValue("ProxyEnable", 1)
            'Test.SetValue("Level", "Intermediate")
            'Test.SetValue("ID", 123)
            'Test.Close()
            My.Computer.Registry.CurrentUser.CreateSubKey("Test")
        End Sub
    End Class
    Just trying different things, I tried setting the viewandmodify to HKEY_Current_User then use the OpenSubKey but that didn't work either :S

    Any help would be great

    Mita

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Edit Registry Keys

    do you want to edit the registry value? or create one?

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Edit Registry Keys

    VB Code:
    1. Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\microsoft\windows\currentversion\internet settings").SetValue("Value Name", Value)
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  4. #4
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Edit Registry Keys

    I don’t understand this, some people post a question and then leave! How do you expect your question to be answered when it is totally confusing?
    First your title says “Edit Registry Keys”.
    And second you are trying to create a registry SubKey!
    My.Computer.Registry.CurrentUser.CreateSubKey("Test")

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    27

    Re: Edit Registry Keys

    Sorry, I had to go to school then work :S

    I was using a script from the MSDN site as a basis of what I was trying to do, but I wasn't sure exactly what I was trying to do :S

    I will need to setvalue of the EnableProxy to 1, and add 2 more Dword values.

    Will look through and try the responses. Thanks guys

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    27

    Re: Edit Registry Keys

    alright looks like that will almost work but I get an unauthorized Exception handle:

    Code:
    System.UnauthorizedAccessException was unhandled
      Message="Cannot write to the registry key."
      Source="mscorlib"
      StackTrace:
           at System.ThrowHelper.ThrowUnauthorizedAccessException(ExceptionResource resource)
           at Microsoft.Win32.RegistryKey.SetValue(String name, Object value, RegistryValueKind valueKind)
           at Microsoft.Win32.RegistryKey.SetValue(String name, Object value)
           at keytest.Form1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Michael\My Documents\Visual Studio 2005\Projects\keytest\keytest\Form1.vb:line 9
           at System.Windows.Forms.Control.OnClick(EventArgs e)
           at System.Windows.Forms.Button.OnClick(EventArgs e)
           at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
           at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.ButtonBase.WndProc(Message& m)
           at System.Windows.Forms.Button.WndProc(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.Run(ApplicationContext context)
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
           at keytest.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
           at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
    My Code:
    Code:
    Imports Microsoft.VisualBasic
    Imports System
    Imports System.Security.Permissions
    Imports Microsoft.Win32
    <Assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, ViewAndModify:="HKEY_CURRENT_USER")> 
    Public Class Form1
        Dim Test As RegistryKey
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Registry.CurrentUser.OpenSubKey("Software\microsoft\windows\currentversion\internet settings").SetValue("ProxyEnable", 1)
        End Sub
    End Class
    So I will need to edit some settings in the reg and create a Reg_Dword and Reg_sz

    Mita

  7. #7
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Edit Registry Keys

    Specify the V.S.Net version at the start of your thread.
    You need to specify the “writable” parameter of “OpenSubKey” as “True” in order to be able to change, create, and delete values. If you don’t specify the parameter, the default is “False”.

  8. #8
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Edit Registry Keys

    VB Code:
    1. Imports Microsoft.VisualBasic
    2. Imports System
    3. Imports System.Security.Permissions
    4. Imports Microsoft.Win32
    5. <Assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, ViewAndModify:="HKEY_CURRENT_USER")>
    6. Public Class Form1
    7.     Dim Test As RegistryKey
    8.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    9.         Registry.CurrentUser.OpenSubKey("Software\microsoft\windows\currentversion\internet settings", True).SetValue("ProxyEnable", 1)
    10.     End Sub
    11. End Class
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width