none
How can i rename the Local Area Connection??

    Question

  • If in my system thr is more than one Local Area Connection like Local Area Connection2, Local Area Connection3, etc like that i need to change only any one that name. How it can be done using vbscript???
    For single connection i hav done it. 
    Const NETWORK_CONNECTIONS = &H31&

    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(NETWORK_CONNECTIONS)

    Set colItems = objFolder.Items
    For Each objItem in colItems
        If objItem.Name = "Local Area Connection" Then
            objItem.Name = "Office Connection"
        End If
    Next

     how to do if thr is more than one?? I need not to change all the name only the perticular connection alone.

    Thursday, November 05, 2009 5:40 AM

Answers

  • Maybe something like this will work for you ...

    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(NETWORK_CONNECTIONS)

    Set colItems = objFolder.Items
    For Each objItem in colItems
        If Instr(objItem.Name, "Local Area Connection") <> 0 Then
            objItem.Name = Replace(objItem.Name, "Local Area Connection", "Office Connection")
        End If
    Next

    It replaces the "Local Area Connection" string in the name with "Office Connection". 

    If you want different names, put them in an array and use the number at the end to index the array, something like this ...

    aNames = Array("Name_1, "Name_2", "Name_3")
    Set colItems = objFolder.Items
    For Each objItem in colItems
        If Instr(objItem.Name, "Local Area Connection") <> 0 Then
            idx = Replace(objItem.Name, "Local Area Connection", "") - 1
            if not (idx > UBound(aNames)) and idx > -1 then objItem.Name = aNames(idx)
        End If
    Next


    Tom Lavedas
    Thursday, November 05, 2009 4:49 PM

All replies

  • Maybe something like this will work for you ...

    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(NETWORK_CONNECTIONS)

    Set colItems = objFolder.Items
    For Each objItem in colItems
        If Instr(objItem.Name, "Local Area Connection") <> 0 Then
            objItem.Name = Replace(objItem.Name, "Local Area Connection", "Office Connection")
        End If
    Next

    It replaces the "Local Area Connection" string in the name with "Office Connection". 

    If you want different names, put them in an array and use the number at the end to index the array, something like this ...

    aNames = Array("Name_1, "Name_2", "Name_3")
    Set colItems = objFolder.Items
    For Each objItem in colItems
        If Instr(objItem.Name, "Local Area Connection") <> 0 Then
            idx = Replace(objItem.Name, "Local Area Connection", "") - 1
            if not (idx > UBound(aNames)) and idx > -1 then objItem.Name = aNames(idx)
        End If
    Next


    Tom Lavedas
    Thursday, November 05, 2009 4:49 PM
  • Hi Tom thanx for your reply. But wat i need is first it should ask to type the Local Area Connection Name for eg: Local Area Connection3 then it should ask to type the new name like eg:connection . I need it in dis may. Is thr any script. I dont want to put in array.
    Friday, November 06, 2009 11:28 AM