Click here to Skip to main content
13,049,172 members (72,285 online)
Rate this:
Please Sign up or sign in to vote.
See more:
MY code below please any one help me thanks
Dim RemoteUsersHive As RegistryKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.Users, usbdTextBox1.Text)
        Dim SubKeys() As String = RemoteUsersHive.GetSubKeyNames
        For i As Integer = 0 To SubKeys.Length - 1
            If SubKeys(i).Length <> 0 Then
                Dim CurrentKey As RegistryKey = RemoteUsersHive.OpenSubKey(SubKeys(i), True)
                    CurrentKey = CurrentKey.OpenSubKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR", True)
                    CurrentKey.SetValue("Start", 4)

                Catch ex As Exception
                End Try
                CurrentKey = Nothing
            End If

when i supplying ip and click the button disable or enable i m getting error ( object reference set to an instance of an object)

please help me fix
Posted 25-Feb-13 2:20am
Updated 25-Feb-13 2:38am
CodeMaster_Noob 25-Feb-13 8:32am
Put debugger on your code and try finding which line of code causes error.
ryanb31 25-Feb-13 8:38am
Which line of code causes the error?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You never check to see if any of these method calls return anything!

What if the target machine has RemoteRegistry turned off?? That first call to OpenRemoteBaseKey won't return anything, but who cares, right? You just go off assuming that it did and try to execute GetSubKeyNames on it.

Oh, and then there's the CurrentKey.OpenSubKey call you make with a FULLY QUALIFIED PATH instead of a RELATIVE path. If you already have the complete path to the target key, why are you even bothering with all the enumeration of subkeys??

And finally, all you're doing is just setting a value in the registry which won't take effect until the machines next boot. I hope this is what you want.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100