Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


jeff.sadowski

Script to rename Network Connection

Recommended Posts

I recently installed openvpn on my server and one client. I wanted to setup a script to install the rest of the clients the part that is difficult is renaming the Network connection.

Is there a tool that will list the network connections and their drivers? either as command line tools or

Something that has a similar output to

|driver|------------------------------------------------|networkconnection|

|Realtek PCIe GBE Family Controller--------|Local Area Connection|

|TAP-Win32 Adapter V9|------------------------|Local Area Connection 2|

I want to create some sort of script be it batch or cscript to find the connection with the driver

TAP-Win32 Adapter V9 and rename it from its current name to tap0901

I didn't find any tools but with some registry hacking I created the following script to modify the name of the network device to what is in my client.ovpn configuration file


setlocal EnableDelayedExpansion
set "networkfile=%HOMEDRIVE%%HOMEPATH%\networks.reg"
set "driversfile=%HOMEDRIVE%%HOMEPATH%\nodes.txt"
set "openvpncfg=%ProgramFiles%\OpenVPN\config\client.ovpn"

regedit.exe /e "%networkfile%" HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}
type "%networkfile%" | findstr "NetCfgInstanceId DriverDesc" > "%driversfile%"
del "%networkfile%"

set "node="
FOR /F "tokens=1,2 delims==" %%A IN ('type "%driversfile%"') DO (
set "lastnode=!node!"
set "node=%%B"
set "test=%%A"
if [!test!] == ["DriverDesc"] (
if [!node!] == ["TAP-Win32 Adapter V9"] (
set "TAPINTERFACE=!lastnode:~1,-1!"
)
)
)
type "%openvpncfg%" | findstr dev-node > "%driversfile%"
FOR /F "tokens=1,2" %%A IN ('type "%driversfile%"') DO (
if [%%A] == [dev-node] (
set "nodename=%%B"
)
)
del "%driversfile%"

echo Windows Registry Editor Version 5.00 > "%networkfile%"
echo. >> "%networkfile%"
echo [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%TAPINTERFACE%

\Connection] >> "%networkfile%"
echo "Name"="%nodename%" >> "%networkfile%"

regedit.exe /s "%networkfile%"
del "%networkfile%"

Edited by jeff.sadowski

Share this post


Link to post
Share on other sites

Tip: avoid using ControlSetxxx when using scripts locally from within the running OS - use instead CurrentControlSet - this avoids a problem where nothing appears to happen because the control set in use is something other than 001 (e.g. Last Known Good has ever been invoked on that machine).

If you were running offline or remotely, then there is no "CurrentControlSet", and instead you would need to look at the data held in the REG_DWORD value named Current under the key HKEY_LOCAL_MACHINE\SYSTEM\Select, then use this (padded out to 3 digits) to open keys & read values under HKEY_LOCAL_MACHINE\SYSTEM\ControlSetxxx.

Just a heads-up in case you find the script works on most, but not all the clients ;)

Share this post


Link to post
Share on other sites

I recently installed openvpn on my server and one client. I wanted to setup a script to install the rest of the clients the part that is difficult is renaming the Network connection.

Is there a tool that will list the network connections and their drivers? either as command line tools or

This seems like an example of where WMI/WMIC may come useful.

Only partially UNrelated:

jaclaz

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...