how do i run my shell Shell("netsh interface ip set address" & Chr(34) & "Local Area Connection" & Chr(34) & "static 10." & IPAddy & ".4") as admin? PLZ

Dani AI

Generated

Short answer: netsh needs an elevated token. A plain Shell() call won't elevate your process, and runas.exe (what suggested) is not the same as asking Windows for elevation via UAC — it either prompts for alternate credentials or does nothing visible if you don't supply them. To get the interactive UAC prompt from a VB.NET app use ShellExecute with the runas verb (or make the whole app require admin via a manifest).

A simple VB.NET pattern (replace the arguments string with the netsh arguments you build) is:

Dim arguments As String = "<build your netsh args here>"
Dim psi As New ProcessStartInfo()
psi.FileName = "netsh.exe"
psi.Arguments = arguments
psi.Verb = "runas"          ' request elevation
psi.UseShellExecute = True

Try
    Process.Start(psi)
Catch ex As System.ComponentModel.Win32Exception
    ' User cancelled elevation or elevation failed
End Try

If elevation must be silent or unattended, do not use stored admin passwords (security risk). Alternatives: mark the EXE with a manifest requesting requireAdministrator, create a Scheduled Task set to run with highest privileges and trigger it from your app, or perform the change from a service already running as SYSTEM. Confirm the adapter name exactly (Windows often uses "Ethernet" or suffixed names), test the netsh command manually from an elevated command prompt first, and remember you cannot redirect stdout/stderr when using UseShellExecute = True.

Background reading: ProcessStartInfo Verb usage and the Win runas tool are documented by Microsoft:
ProcessStartInfo.Verb

How User Account Control (UAC) works

Recommended Answers

All 2 Replies

I am assuming that 'IPAddy' Is a variable declared the contains a number in the x.x format.
Try Using This:

Shell("runas.exe /users:administrator netsh interface ip set address" & Chr(34) & "Local Area Connection" & Chr(34) & "static 10." & IPAddy & ".4")

I am assuming that 'IPAddy' Is a variable declared the contains a number in the x.x format.
Try Using This:

Shell("runas.exe /users:administrator netsh interface ip set address" & Chr(34) & "Local Area Connection" & Chr(34) & "static 10." & IPAddy & ".4")

Yea i tried that nothing happens. thanks for the suggestion.

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.