The first part of my code runs like I want, but when I go to make the account admin using net localgroup administrators the code crashes and i get a message saying "Read our privacy statement online..." so i'm assuming my code is setting off some red flags in my pc. I just want this code to run right and I'm not sure how to fix an issue like this.
#include <iostream>
#include <string>
#include <stdio.h>
#include <cstdlib>
int main()
{
std::string name;
std::string admin;
std::string pass;
std::string full;
std::string mkusr;
std::string mkadm;
std::string wait;
std::string passreq;
std::string times;
std::string passchg;
std::string comment;
std::string expires;
std::cout << "What is the new username?\n";
getline (std::cin, name);
std::cout << "What is the full name? FIRSTNAME MIDDLEINITIAL LASTNAME\n";
getline (std::cin, full);
std::cout << "What password should "<< name <<" have?\n";
getline (std::cin, pass);
std::cout << "Is " << name << " an admin?\nY or N\n";
getline (std::cin, admin);
std::cout << "Does " << name << " need to have a password\nY or N\n";
getline (std::cin, passreq);
std::cout << "When is "<< name <<" authorised to be on? For 24/7 access please enter all\n\nFormat <M,T,W,Th,F,Sa,Su OR M-Su>,<1AM-12PM OR 01:00-23:00>\nTo input multiple time across different days use the ; symbol \nEXAMPLE: M,4AM-5PM;T,1PM-3PM;W-F,8:00-17:00\n";
getline (std::cin, times);
std::cout << "Is " << name << " allowed to change his/her password\nY or N\n";
getline (std::cin, passchg);
std::cout << "Please give a description for " << name << "\n";
getline (std::cin, comment);
std::cout << "When will " << name << "s account expire? If it will never expire please type never\nFormat <MM/DD/YYYY> OR <DD/MM/YYYY> OR <mmm,dd EX:jan,9>\n";
getline (std::cin, expires);
system ("cls");
mkusr = "net user ";
mkusr += name;
mkusr += " ";
mkusr += pass;
mkusr += " /add ";
if (passreq == "Y"){
mkusr += " /passwordreq:yes";
}
else {
mkusr += " /passwordreq:no";
};
mkusr += (" /times:");
times = '"' + times +'"';
mkusr += times;
mkusr += " /fullname:";
full = '"' + full +'"';
mkusr += full;
if (passchg == "Y"){
mkusr += " /passwordchg:yes";
}
else{
mkusr += " /passwordchg:no";
};
mkusr += " /comment:";
comment = '"' + comment +'"';
mkusr += comment;
mkusr += " /expires:";
expires = '"' + expires +'"';
mkusr += expires;
//net user 'name' 'pass' /add /passwordreq:'yes/no' /times:'times' /fullname:"'full name'" /passwordchg:'yes/no' /expires:'mm/dd/yyyy||dd/mm/yyy||never' /comment:'cmt'
//times format M,4AM-5PM;T,1PM-3PM;M-F,08:00-17:00 all
std::cout << mkusr;
const char* mkuser = mkusr.c_str();
system(mkusr.c_str());
//system("net user /add << name << pass << /FULLNAME:<<full<<");
// THIS IS THE PROBLEM AREA
if (admin == "Y"){
std::cout << "Ok, I will make " << name << " an admin\n Please press any key to make "<< name <<"an admin.";
getline (std::cin, wait);
mkadm = "net localgroup administrators ";
mkadm += name;
mkadm += " /add";
std::cout << "\n " << mkadm;
const char* mkadm = mkadm;
system(mkadm);
//system("net localgroup administrators << name << /add");
// THIS IS THE PROBLEM AREA
}
getline (std::cin, wait);
return 0;
}
Sorry for the horrible formatting
Aucun commentaire:
Enregistrer un commentaire