If I wanted to disable a specific NIC on Widows, this is how I'd typically do it:
wmic.exe path win32_networkadapter where "NetConnectionID = 'Local Area Connection 2'" call disable
From an elevated permissions / run as administrator command line prompt... and it works, life is good.
So I compiled this simple C++ CLI app:
#include "stdafx.h"
#include <string>
#include <iostream>
#include <cstdio>
#include <memory>
#ifndef popen
FILE *__cdecl popen(const char *_Command, const char *_Mode) { return _popen(_Command, _Mode); }
#endif
#ifndef pclose
int __cdecl pclose(FILE *_Stream) { return _pclose(_Stream); }
#endif
std::string exec(const char* cmd) {
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
if (!pipe) return "ERROR";
char buffer[128];
std::string result = "";
while (!feof(pipe.get())) {
if (fgets(buffer, 128, pipe.get()) != NULL) result += buffer;
}
return result;
}
int main() {
std::cout << exec("wmic path win32_networkadapter where ""NetConnectionID = 'Local Area Connection 2'"" call disable");
return 0;
}
Which I execute from the same, elevated permissions command line prompt... but the response I get back is:
C:\elevatesdh\Debug>elevatesdh.exe
Invalid Verb.
What gives?