I am working on an hotspot maker application for which i am using c++ to execute netsh commands in cmd, but for that i require administrative privileges of cmd. I have used system(runas \\user:) but that is giving an unknown error.
My admin user:the_annoying_
PC NAme: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;
}
The easiest solution I think would be to just run your compiled Application as an Administrator this way alls subprocesses will be executed with Admin privileges as well (so the process of system()).
#include <iostream>
{
system("whoami");
return 0;
}
sudo ./test => root
./test => username
Should be the same on Windows.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.