编程系统调用WDCI意外行为(提升的权限)
Programmatic system call WDCI Unexpected Behavior (Elevated Permissions)
如果我想禁用Widows上的特定NIC,我通常会这样做:
wmic.exe path win32_networkadapter where "NetConnectionID = 'Local Area Connection 2'" call disable
从提升的权限/以管理员身份运行命令行提示符。。。它是有效的,生活是美好的。
所以我编译了这个简单的C++CLI应用程序:
#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;
}
我从相同的提升权限命令行提示符执行。。。但我得到的回复是:
C:elevatesdhDebug>elevatesdh.exe
Invalid Verb.
什么东西?
我想你必须更改这一行
std::cout << exec("wmic path win32_networkadapter where ""NetConnectionID = 'Local Area Connection 2'"" call disable");
至
std::cout << exec("wmic path win32_networkadapter where "NetConnectionID = 'Local Area Connection 2'" call disable");
但我可能大错特错。。。
相关文章:
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- 如果整个应用程序是虚拟映射的,为什么 new 会进行系统调用?
- 如何将C++系统调用连接到 freertos
- 如何使用 C/C++ 和 system() 系统调用以外的其他方法在 Linux 中获取文件功能?
- 系统调用:一次和多次,哪个更好?
- 使用路径和空格的系统调用
- 是否有等效于 macOS 上的 clone() 系统调用?
- 从C++调用系统调用节点?
- C++测试程序中的非法系统调用(对角矩阵元素程序的总和)
- 英特尔 Pin:如何获取系统调用的返回地址
- 如何使用低级系统调用从 stdin 和输入文件中获取字节数
- 使用模拟器C++从RISC-V裸机程序调用printf系统调用时失败
- 动态执行的 ARM ASM 系统调用,可从C++重新定位
- 如何知道我正在使用的Linux OS是否具有特定的系统调用
- 当C 中的系统调用conconculables时,参数字符串中的字符损失
- 调用系统调用函数时出现异常
- 在 boost::asio 中自定义套接字/关闭系统调用
- 系统调用失败"Incorrect Section Name -e" C++
- 编程系统调用WDCI意外行为(提升的权限)
- mkdir系统调用创建权限0755,而不是0777