heres the script basically it sets (supposed to) Local area connection ipv4 static ip address to 10.XX.XX.2 but it dosent work it works fine if you run cmd as addy and put the script in netsh interface ip set address "Local Area Connection" static 10.XX.XX.2

Dim txtlen As Integer = Len(TextBox2.Text)
        Dim IPAddy As String = ""
        Dim asciiSplit(4) As Char
        asciiSplit = TextBox2.Text.ToCharArray
        If txtlen = 1 Then IPAddy = "0." & asciiSplit(0).ToString
        If txtlen = 2 Then IPAddy = "0." & asciiSplit(0).ToString & asciiSplit(1).ToString
        If txtlen = 3 Then IPAddy = asciiSplit(0).ToString & "." & asciiSplit(1).ToString & asciiSplit(2).ToString
        If txtlen = 4 Then IPAddy = asciiSplit(0).ToString & asciiSplit(1).ToString & "." & asciiSplit(2).ToString & asciiSplit(3).ToString

        Shell("netsh interface ip set address" & Chr(34) & "Local Area Connection" & Chr(34) & "static 10." & IPAddy & ".4")

        Process.Start("http:\\10." & IPAddy & ".2")
    End Sub

Dani AI

Generated

— quick diagnosis and practical fixes based on the thread: the change only succeeds when you run an elevated command prompt, which strongly suggests a permissions/UAC issue and/or a wrong adapter name. Changing TCP/IP requires administrator rights, and hard-coding a connection name (like the classic “Local Area Connection”) is brittle because names vary by machine and OS. Also, launching external commands from your app via the old Shell call can invoke a different execution context and won’t automatically get elevated.

A more robust route is to call the networking API from .NET (WMI). It avoids fragile command-line quoting and lets you pick the adapter programmatically (match by NetConnectionID). Add a reference to System.Management and use the Win32_NetworkAdapterConfiguration methods (EnableStatic / SetGateways). Example VB.NET pattern:

' add reference to System.Management
Imports System.Management

Sub SetStaticIP(adapterName As String, ip As String, mask As String, gateway As String)
    Dim q As New SelectQuery("Win32_NetworkAdapterConfiguration", "IPEnabled = True")
    Using searcher As New ManagementObjectSearcher(q)
        For Each mo As ManagementObject In searcher.Get()
            If mo("NetConnectionID") IsNot Nothing AndAlso mo("NetConnectionID").ToString() = adapterName Then
                Dim p = mo.GetMethodParameters("EnableStatic")
                p("IPAddress") = New String() { ip }
                p("SubnetMask") = New String() { mask }
                mo.InvokeMethod("EnableStatic", p, Nothing)

                Dim g = mo.GetMethodParameters("SetGateways")
                g("DefaultIPGateway") = New String() { gateway }
                g("GatewayCostMetric") = New Integer() { 1 }
                mo.InvokeMethod("SetGateways", g, Nothing)
                Exit For
            End If
        Next
    End Using
End Sub

If you prefer netsh, start it elevated from your app so Windows prompts for admin (ProcessStartInfo with UseShellExecute = True and Verb = "runas") rather than relying on Shell. Also, when launching the robot web page, use a proper URL (forward slashes).

Troubleshooting checklist: run your exact command manually in an elevated command prompt to verify syntax; verify the adapter name in Network Connections or enumerate NetConnectionID; ensure the app runs with administrator privileges (manifest or runas); consider packaging a small signed helper that does the IP switch so students get a single prompt. ’s registry route is an option, but WMI or an elevated helper is generally more reliable and immediate.

Recommended Answers

All 3 Replies

try using this msfn.org page to help create the program. Wont use shell scripts, but changes IP within the program using some registry values.

it is in vb6 so some will have to be converted for .net

I need to figure out how to change static ip address to say 10.xx.xx.2 the would be an input but its for communicating with a robot network adapter the computer needs to be at that ip for it to work and doing it manually is to hard for students and rookie teams to do. any help would be greatly appreciated. p.s i tried netsh commands but they have to be exicuted one bye one not together such as

netsh interface ipv4 set address "local area connection" static 10.xx.xx.2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.