how to convert System::String to const char*?

You can do this using the msclr::interop::marshal_context class:

#include <msclr/marshal.h>

Then:

String^ something = "something";

msclr::interop::marshal_context ctx;
const char* converted = ctx.marshal_as<const char*>(something);

system(converted);

The buffer for converted will be freed when ctx goes out of scope.

But in your case it would be much easier to just call an equivalent managed API:

System::Diagnostics::Process::Start("netsh", "the args");

Leave a Comment