Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
MY code below please any one help me thanks
VB
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)
                Try
                    CurrentKey = CurrentKey.OpenSubKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR", True)
                    CurrentKey.SetValue("Start", 4)


                Catch ex As Exception
                    MessageBox.Show("Done")

                End Try
                CurrentKey = Nothing

            End If
        Next


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
Updated 25-Feb-13 2:38am
v2
Comments
[no name] 25-Feb-13 8:32am    
Put debugger on your code and try finding which line of code causes error.
ZurdoDev 25-Feb-13 8:38am    
Which line of code causes the error?

1 solution

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.
 
Share this answer
 

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