远程启用/禁用远程NIC的问题 [英] Problem with remotely enabling/disabling remote NIC

查看:136
本文介绍了远程启用/禁用远程NIC的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码在本地计算机上禁用我的vmware NICS.问题是,当我在列表视图中有计算机,然后尝试在列表视图中遍历计算机时,我的NIC不会远程启用或禁用,但是在主机上,NIC会启用或禁用.我需要帮助来遍历列表视图中的计算机对象,并在列表视图中的计算机而非主机上禁用或启用NICS.任何帮助表示赞赏.

I have the code below that disables my vmware NICS on my local computer. The problem is when I have computers in my listview and then I try to loop through the computers in my listview my NICs will not enable or disable remotely but on my host machine the NICs will enable or disable. I would like help to loopthrough the computers objects in my list view and disable or enable the NICS on the computers in my listview and not host machine.. I have attached the code below. Any help is appreciated.

On Error Resume Next
       Dim cname As ListViewItem
       For Each cname In ListView1.Items
           Debug.WriteLine(cname)
           ' Const ssfCONTROLS = 3
           Dim ssfCONTROLS
           ssfCONTROLS = 3
           Dim vmNic1 = "VMnet1"
           Dim vmNic2 = "VMnet8"

           Dim sDisableVerb As String = "Disable"
           Dim sEnableVerb As String = "Enable"


           Dim ShellApp As New Shell32.Shell()
           Dim oControlPanel As Shell32.Folder = ShellApp.NameSpace(ssfCONTROLS)
           Dim folderitem As Shell32.FolderItem
           Dim oNetConnections As Shell32.Folder = Nothing
           Dim oLanConnection As Shell32.FolderItem = Nothing
           'Dim Verb As String = Nothing


           'oNetConnections = Nothing
           For Each folderitem In oControlPanel.Items()
               Debug.WriteLine("Loop 1: " & folderitem.Name)
               If folderitem.Name = "Network Connections" Then
                   Debug.WriteLine("Loop 2: " & folderitem.Name)
                   oNetConnections = folderitem.GetFolder
                   Exit For
               End If
           Next
           For Each folderitem In oNetConnections.Items
               If folderitem.Name.Contains(vmNic1) Then
                   Debug.WriteLine("Loop 3: " & folderitem.Name)
                   oLanConnection = folderitem
               End If

           Next
           For Each Verb As Shell32.FolderItemVerb In oLanConnection.Verbs
               If Verb.Name = "En&able" Then
                   Verb.DoIt()
                   Exit For
               End If
           Next
           For Each folderitem In oNetConnections.Items
               If folderitem.Name.Contains(vmNic2) Then
                   Debug.WriteLine("Loop 3: " & folderitem.Name)
                   oLanConnection = folderitem
               End If
           Next
           For Each Verb As Shell32.FolderItemVerb In oLanConnection.Verbs
               If Verb.Name = "En&able" Then
                   Verb.DoIt()
                   Exit For
               End If

           Next

推荐答案

由于要通过Shell对象来执行此操作,您将不得不在远程计算机上创建Shell对象.在主机上执行此操作仅适用于主机.

而不是这样做:
Since you''re going through a Shell object to do this, you''d have to create the Shell object on the remote machine. Doing it on the host machine will work for ONLY the host machine.

Instead of doing this:
Dim ShellApp As New Shell32.Shell()


您必须执行以下操作:


You''d have to do something like this:

Dim ShellApp As Shell32.Shell
ShellApp = CreateObject( "Shell32.Shell", "<remotemachinenamehere>" )</remotemachinenamehere>


如果可以使用,我没有任何想法!您必须自己尝试.

可以使用WMI和Win32_NetworkAdapter类,但只能在Vista或更高版本的计算机上启用和禁用adpaters.此方法不适用于Windows XP和更低版本的Windows.

我记得很久以前(超过12年)做过类似的事情,但是我使用 IPHelper做到了API [ ^ ]和VB6.


I HAVE NO IDEA IF THIS WILL WORK! You''ll have to try it yourself.

WMI and the Win32_NetworkAdapter class can be used, but you can only Enable and Disable adpaters on a Vista or above machine. This method won''t work on Windows XP and below.

I remember doing something similar to this a long time ago (12+ years), but I did it using the IPHelper API[^] and VB6.


这篇关于远程启用/禁用远程NIC的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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