如何使用 c++ 在 cmd 中使用管理员权限执行命令
How to excetute commands in cmd with adminstritive privelges using c++?
我正在开发一个热点制作器应用程序,我正在使用c ++在cmd中执行netsh命令,但为此我需要cmd的管理权限。但这给出了一个未知的错误。
我的管理员用户:the_annoying_
电脑号码:Unknown_God
using namespace std;
int main ()
{
string name;
cout << "Enter Name of Wifi Hotspot:" << endl;
cin >> name;
string pass1="0",pass2="1";
while(pass1!=pass2)
{
cout << "Enter the password" << endl;
cin >> pass1;
cout << "Re-enter the password" << endl;
cin >> pass2;
if(pass1!=pass2)
{
cout << "Please enter same passwords" << endl;
}
}
cout << "Working..." << endl;
string command="netsh wlan set hostednetwork mode=allow ssid=" + name + "key=" + pass1;
const char *command1=command.c_str();
cout << "Creating Wifi Hotspot using given Credentials" << endl;
system("runas /user:the_annoying_ command1");
string comm="netsh wlan start hostednetwork";
const char *command2=comm.c_str();
system("runas /user:the_annoying_ command2");
cout << "Hotspot Sucessfully Created" << endl;
}
我认为
最简单的解决方案是以管理员身份运行编译的应用程序,这样所有子进程也将以管理员权限执行(因此system((的进程(。
#include <iostream>
{
system("whoami");
return 0;
}
sudo ./test =>根
./test =>用户名
在Windows上应该相同。
相关文章:
- 在没有管理员权限的情况下连接到同一网络中的命名管道
- 在没有管理员权限的情况下,在 c++ 中以编程方式将程序添加到启动
- 具有管理员权限的外壳执行不会结束
- 如何在Qt中请求管理员权限?
- CreateProcess() 可以授予管理员权限吗?
- 如何使用管理员权限运行 EXE
- QSettings没有管理员权限不保存ini更改
- 在没有管理员权限的情况下安装 Vulkan SDK
- 如何使用 c++ 在 cmd 中使用管理员权限执行命令
- 在没有管理员权限的情况下安装C++编译器
- 如何在不使用 C++ 中的管理员权限的情况下设置 AD 属性值
- 以 Windows 服务身份运行应用程序是否需要管理员权限
- Windows 7如何确定您是否需要管理员权限?(vc60)
- 是否可以调整令牌权限提升为管理员权限
- 管理员权限2个应用程序
- 如何运行需要管理员权限的应用程序
- >使用 RegCreateKeyEx() 的 Windows 可执行文件不会提示输入 UAC 管理员权限并失败?
- 如何在 c++ 中启动具有管理员权限的应用程序
- 如何在C++中以管理员权限运行 ShellExecute
- 如何通过C++检查我的程序是否在管理员权限下运行