OnlyTwentyCharacters
OnlyTwentyCharacters

Reputation: 23

VB.NET Process.Start Arguments not passing to CMD

This is my first post here, so please go easy, I also have a good knowledge of VB.

I am making an app that is to create a WiFi hotspot at a click of a button so that I can use my laptop as a WiFi extender for my devices like my phone, however, I am doing this with command prompt. This is my code so far:

      Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    Dim startInfo As New ProcessStartInfo("cmd")
    startInfo.WindowStyle = ProcessWindowStyle.Minimized
    startInfo.Arguments = "netsh show wlan drivers"
    Process.Start(startInfo)
End Sub

The problem is, it's not passing the arguments. Cmd launches fine but receives nothing.

Things I have tried: 1. Using process.start and ProcessStartInfo 2. Change working directory 3. Send arguments after cmd has launched (after process.start) 4. Change target framework 5. Run in x86 and x64 6. Run as administrator 7. Trying other commands such as "color 2f". Failed.

Any help would be greatly appreciated!

Edit: Not even the WindowStyle argument was passed.

Upvotes: 1

Views: 4869

Answers (1)

Steve
Steve

Reputation: 216348

You need to add

startInfo.Arguments = "/C netsh wlan show drivers"

without that flag (/C) the CMD command exits immediately and nothing is executed

In any case your command is wrong. The correct syntax is

netsh wlan show drivers

You could change your code to capture the output of the command in this way

Dim startInfo As New ProcessStartInfo("cmd")
startInfo.WindowStyle = ProcessWindowStyle.Minimized
startInfo.Arguments = "/C netsh wlan show drivers"
startInfo.RedirectStandardOutput = true
startInfo.UseShellExecute = false
startInfo.CreateNoWindow = true
Dim p = Process.Start(startInfo)
Dim result = p.StandardOutput.ReadToEnd()
p.Close()

Upvotes: 2

Related Questions