|
-
Aug 28th, 2006, 03:10 PM
#1
Thread Starter
Junior Member
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
-
Aug 28th, 2006, 03:19 PM
#2
Re: Edit Registry Keys
do you want to edit the registry value? or create one?
-
Aug 28th, 2006, 03:29 PM
#3
Re: Edit Registry Keys
VB Code:
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
-
Aug 28th, 2006, 03:38 PM
#4
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")
Last edited by VBDT; Aug 28th, 2006 at 07:29 PM.
-
Aug 29th, 2006, 01:06 AM
#5
Thread Starter
Junior Member
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
-
Aug 29th, 2006, 01:11 AM
#6
Thread Starter
Junior Member
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
-
Aug 29th, 2006, 03:15 AM
#7
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”.
-
Aug 29th, 2006, 06:42 AM
#8
Re: Edit Registry Keys
VB 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", True).SetValue("ProxyEnable", 1)
End Sub
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|