USB禁用使用IP地址vb代码我收到错误 [英] USB Disable using IP Address vb code I am getting error

查看:75
本文介绍了USB禁用使用IP地址vb代码我收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下我的代码请任何人帮助我谢谢

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





当我提供ip并单击按钮禁用或启用即时获取错误(对象参考设置为一个对象的实例)



请帮我修复



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

推荐答案

你永远不会检查是否有任何这些方法调用返回任何内容!



如果目标机器关闭RemoteRegistry怎么办?首次调用OpenRemoteBaseKey不会返回任何内容,但谁在乎呢,对吧?你只是假设它已经完成并尝试在其上执行GetSubKeyNames。



哦,然后就是 CurrentKey.OpenSubKey 使用FULLY QUALIFIED PATH而不是RELATIVE路径调用。如果你已经拥有了目标键的完整路径,为什么还要烦恼所有的子键枚举?



最后,你所做的一切只是在注册表中设置一个值,直到机器下次启动才会生效。我希望这就是你想要的。
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.


这篇关于USB禁用使用IP地址vb代码我收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆