1

In Windows IOT - is there an option via command line to delete unplugged (hidden) Ethernet adapters?

My issue is, when I am plug in an USB-TO-ETHERNET device adapter, it is have the name, lets say, "Ethernet 2". Then I want to set static ip like -

netsh int ip set address "Ethernet 2" static 123.0.0.123 255.255.255.0 0.0.0.0

But when I am unplug the above adapter, and plug it to another USB port, it is have the name, lets say, "Ethernet 3".

"Ethernet 2" is not appear anymore, for example in ipconfig.

And when I set static ip for the new one ("Ethernet 3") with same details, like

netsh int ip set address "Ethernet 3" static 123.0.0.123 255.255.255.0 0.0.0.0

I am getting the error -

The object already exists.

I tried to reset "Ethernet 2" to DHCP without success -

netsh int ip set address "Ethernet 2" dhcp

But I am getting the error below:

The filename, directory name, or volume label syntax is incorrect.

Any idea how to overcome this issue? To forget the settings of "Ethernet 2" and apply it on "Ethernet 3".

Thanks.

0

I am not sure if Win10 IoT supports vbscript.
It needs the command line tool "devcon.exe"
I copied it from my bigger solution, i didnt checked for missing code.

Today i would write it with powershell.
But you will get the idea.

Set goFileSystem = CreateObject( "Scripting.FileSystemObject" )
Set oWshShell = CreateObject("WScript.Shell")
Set oWshSysEnv = oWshShell.Environment( "PROCESS" )
sTempDir   = oWshSysEnv( "TEMP" )

'Create NIC hardware information
'
'Get all NIC entries (contains present / active and hidden / inactive devices)
sNICAllLogFile       = sTempDir & "\NICAll.log"
sCommandLine = "cmd /c devcon.exe findall =net ""PCI*"" > " &  sNICAllLogFile
lRetVal = oWshShell.Run( sCommandLine, 1, True )
If 0 <> lRetVal Then
   Wscript.Quit (-5)
End If
'Get present NIC (contains only present / active devices)
sNICPresentLogFile       = sTempDir & "\NICPresent.log"
sCommandLine = "cmd /c devcon.exe find =net ""PCI*""> " &  sNICPresentLogFile
lRetVal = oWshShell.Run( sCommandLine, 1, True )
If 0 <> lRetVal Then
   Wscript.Quit (-5)
End If

'Read files with NIC information and compare present NIC with all NIC entries
Set fileAllNIC = goFileSystem.OpenTextFile( sNICAllLogFile, 1, False, 0 )
sPresentNIC = goFileSystem.OpenTextFile( sNICPresentLogFile, 1, False, 0 ).ReadAll()

Do While Not ( fileAllNIC.atEndOfStream )
   aSplitString = Split (fileAllNIC.ReadLine(), ":", -1, 1)
   strLine = Trim(aSplitString(0))
   if instr(1, strLine, "matching device", vbTextCompare) = 0 Then
      'Check if NIC entry " & strLine & " is present..."
      If instr(1, sPresentNIC, strLine, vbTextCompare) > 0 Then
         '-> NIC present. Nothing to do..."
      else
         'Delete obsolete entries
         '-> NIC not present. Removing entry..."
         sCommandLine = "cmd /c devcon.exe remove ""@" & strLine & """"
         lRetVal = oWshShell.Run( sCommandLine, 1, True )
         If 0 <> lRetVal Then
            'Error: devcon failed !
            Wscript.Quit (-5)
         End If
      end if
   end if
Loop
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.