I wrote a BAT
script that automatically connects and disconnects a broad band connection:
netsh mbn connect interface="Mobile Broadband Connection" connmode=name name="My Provider"
netsh mbn disconnect interface="Mobile Broadband Connection"
When I click the BAT
script it is working fine, but when I execute it with Process.Start
:
var startInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = "/c reconnect.bat",
WindowStyle = ProcessWindowStyle.Minimized,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
var process = new Process
{
StartInfo = startInfo
};
process.Start();
netsh returns an error that the mbn command was not found.
Before I was using a BAT
file I started the commands directly. They worked fine on the shell, but got the same error when using Process.Start
.
Why is this happening to me?
Output:
C:\Dev\NetworkAdapterTest\NetworkAdapterTest\bin\Debug>netsh mbn connect interface=\"Mobile Breitbandverbindung\" connmode=name name=\"A1 2\" The following command was not found: mbn connect interface="Mobile Breitbandverbindung" connmode=name name="A1 2".
C:\Dev\NetworkAdapterTest\NetworkAdapterTest\bin\Debug>netsh mbn disconnect interface=\"Mobile Breitbandverbindung\" The following command was not found: mbn disconnect interface="Mobile Breitbandverbindung"
Notice how the quoting is really wired. I got the same issues when I started the commands directly.
When I compile the solution with Visual Studio 2008 everything is working as intended.
Question is no longer relevant.