Results 1 to 2 of 2

Thread: Renaming network connection script

  1. #1
    Join Date
    Jun 2009
    Posts
    4

    Renaming network connection script

    I want a script to rename a specific network connection from "Local area connection" to "Nomad". Since we have computers with different language settings. We want to rename the network conneciton on the bases of the network adapter that is being used by the network connection. The name of the network adapter is "Cisco systems VPN adapter". The main concern is that there are many network connection and network adapters would vary from computer to computer. I came across two scripts one of which would give me data for network connections and the other would give me data for network adapter. If I can find a ways to merge the to records and then get the name of the network connection associated with the network adapter which I want to rename that would resolve my issue.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Renaming network connection script

    Code:
    Dim strKeyPath : strKeyPath = "SYSTEM\CurrentControlSet\Control\Network"
    Dim objShell : Set objShell = CreateObject("Wscript.Shell")
    Const HKEY_LOCAL_MACHINE = &H80000002
    Dim strMacAddress
    Dim strNetWorkConnection
    strNetWorkConnectionNEW = "Your New Name"
    strComputer = "."
            
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery  ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
     
    For Each Item In colItems
    	If Not IsNull(Item.MACAddress) Then strMacAddress = Item.MACAddress
    Next
            
    Dim objRegistry : Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
            
    objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
    For Each objSubkey In arrSubkeys
    	If InStr(objSubkey,"{") Then
    		objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath &"\" &objSubkey, arrSubkeys2
    		For Each objSubkey2 In arrSubkeys2
    			If InStr(objSubkey2,"{") Then
    				objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath &"\" &objSubkey &"\" &objSubkey2, arrSubkeys3
    				For Each objSubkey3 In arrSubkeys3
    					If Instr(objSubkey3,"Connection") Then
    						objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath &"\" &objSubkey &"\" &objSubkey2 &"\" &objSubkey3,"Name",strNetworkName
    						objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath &"\" &objSubkey &"\" &objSubkey2 &"\" &objSubkey3,"PnpInstanceID",strPNPInstance
    						If Not IsNull(strNetworkName) Then
    							If Not IsNull(strPNPInstance) Then                                                
    								Set colItems = objWMIService.ExecQuery  ("SELECT * FROM Win32_NetworkAdapter Where MACAddress = " &"'" &strMacAddress &"'")
    								For Each objItem In colItems
                                    	If strPNPInstance = objItem.PNPDeviceID Then strNetWorkConnection = strNetworkName
                                	Next
                            	End If
                        	End If
                    	End If
                	Next
    			End If
    		Next
    	End If
    Next
     
    objShell.Run "netsh interface set interface " &Chr(34) &strNetWorkConnection &Chr(34) &" DISABLE",0,True
    objShell.Run "netsh interface set interface name = " &Chr(34) &strNetWorkConnection &Chr(34) &" newname = " &Chr(34) &strNetWorkConnectionNEW &Chr(34),0,True
     
    WScript.Echo "Script Finished"

Similar Threads

  1. Powershell Script to Enable/Disable Network Connection
    By windows_user in forum Software Development
    Replies: 8
    Last Post: 27-04-2012, 09:35 PM
  2. Tips to optimize your Network Connection and Wireless Connection
    By Computer_Freak in forum Tips & Tweaks
    Replies: 3
    Last Post: 18-01-2012, 08:30 PM
  3. Replies: 1
    Last Post: 06-07-2011, 07:43 AM
  4. Linux bash script for telnet connection
    By Rubero in forum Software Development
    Replies: 5
    Last Post: 23-08-2010, 09:08 PM
  5. Bash script for internet connection in Ubuntu
    By Callium in forum Operating Systems
    Replies: 5
    Last Post: 23-01-2010, 05:42 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,134,865.56751 seconds with 16 queries