Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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)
                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 25-Feb-13 3:20am
Edited 25-Feb-13 3:38am
RyanDev135.7K
v2
Comments
CodeMaster_Noob at 25-Feb-13 8:32am
   
Put debugger on your code and try finding which line of code causes error.
ryanb31 at 25-Feb-13 8:38am
   
Which line of code causes the error?

1 solution

Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,478
1 OriginalGriff 6,516
2 Peter Leow 3,567
3 Zoltán Zörgő 3,386
4 Richard MacCutchan 2,397


Advertise | Privacy | Mobile
Web03 | 2.8.150123.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2015
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