netsh add profile fails only with c#

0

I have a network profile for a 802.x network which works just fine when run from a batch file or cmd:

wlan add profile filename="config.xml"

So I thought I might as well do this on my C# programme by running a Process:

Process process = new Process()
{
    StartInfo = new ProcessStartInfo
    {
        FileName = "netsh.exe",
        Arguments = String.Format(@"wlan add profile filename=""{0}""", "config.xml"),
        UseShellExecute = false,
        RedirectStandardOutput = true,
        CreateNoWindow = true
    }
};
process.Start();

I asume that the file is being read alright, since otherwise it would output that the file has not been found. That is the C# error output message:

Profile format error 0x80420011: The connection profile is damaged.

But the config.xml is exactly the same!

I also tried running it in a more simple way, but the output is still the same:

string strCmd = "/C netsh wlan add profile filename=\"config.xml\"";
Process.Start("CMD.exe", strCmd);

Is there anything am I missing on my C# code so that this netsh command can be executed correctly?

Edit:
Console, Batch and C# commands were all run with user permissions. However, I tried running the C# one with administrator permissions as well, and it didn't work either.

c#
process
netsh
asked on Stack Overflow Dec 7, 2016 by zurfyx • edited Dec 7, 2016 by zurfyx

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0