שתף באמצעות


Problems writing to Registry "The parameter is incorrect"

Question

Sunday, October 24, 2010 9:53 AM

Hi,

i have a problem writing to the registry. This is my code:

 

    Dim key As Microsoft.Win32.RegistryKey
    key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\codelab3\thumbnailPhoto")
    key.SetValue("MyRegKeyValue", "1234567890")
    key.Close()

 

But i always get the error "The parameter is incorrect". Whats wrong in my code?

Best regards,
Yavuz B.

My Sharepoint and Enterprise 2.0 Blog http://www.starcoder.net
Microsoft Sharepoint Resources & Blogs List

All replies (3)

Sunday, October 24, 2010 11:42 AM ✅Answered

I think you are missing openSubkey and also writing to system registry require administrative priviledge.

 Dim key As Microsoft.Win32.RegistryKey
    key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\codelab3\thumbnailPhoto")
 **   key.OpenSubKey("SOFTWARE\codelab3\thumbnailPhoto",True)
**    key.SetValue("MyRegKeyValue", "1234567890")
    key.Close()

kaymaf

CODE CONVERTER SITE

http://www.carlosag.net/Tools/CodeTranslator/.

http://www.developerfusion.com/tools/convert/csharp-to-vb/.


Monday, October 25, 2010 12:04 AM ✅Answered

Thank you. Thats it. But how i can i make it, that my application asks for administrative privileges under Windows 7? Best regards,
Yavuz B.

My Sharepoint and Enterprise 2.0 Blog http://www.starcoder.net
Microsoft Sharepoint Resources & Blogs List

There are many ways to do this

1) Right click your program executable and click Run As Administrator

2) Do it programmatically, you have to set your program to run as admin during installation http://stackoverflow.com/questions/2313045/how-to-set-run-this-program-as-an-administrator-programatically

3) Embed UAC in your program http://www.professionalvisualstudio.com/blog/2007/10/05/enabling-your-application-for-uac-on-vista/

http://code.msdn.microsoft.com/elevatedprivilegeuac

kaymaf

CODE CONVERTER SITE

http://www.carlosag.net/Tools/CodeTranslator/.

http://www.developerfusion.com/tools/convert/csharp-to-vb/.


Sunday, October 24, 2010 1:39 PM

Thank you. Thats it. But how i can i make it, that my application asks for administrative privileges under Windows 7?Best regards,
Yavuz B.

My Sharepoint and Enterprise 2.0 Blog http://www.starcoder.net
Microsoft Sharepoint Resources & Blogs List