using c++ program to add 100 users to windows server 2008

hello there,
our professor has assigned us this assignment. and he gaves source code to modify too.
As an assistant IT director at SOSU.COM, you are asked by the CEO, Dr. A, to write a program to create/delete a user account (including login name and password) for each user (who can be a student, faculty, or staff) for the Cyber-Space summer program. The detailed information of these users is contained in the file users100.txt which can be downloaded from the blackboard system.

The format of each user record in the file is as follows: FirstName:LastName:DateOfBirth:Status:StudentID:Decision (i.e., first name followed by a colon, then last name followed by a colon, and so on).
• The value of the Status field for a user can be a faculty, staff, freshman, sophomore, junior, or senior.
• The value of the Decision field for a user can be a c (confirmed to participate) or q (quit).

For example, Michael Jordan was born in 2/25/1977 and is a freshman with student ID 123-45-6789 and he has confirmed to participate the program, then the field values of his record in the file will be Michael:Jordan:02-25-1977:freshman:123-45-6789:c. If he decided not to participate the program, the values of this record will be Michael:Jordan:02-25-1977:freshman:123-45-6789:q. You don’t create a user account in your system if the decision value of that record is ‘q’ when your program processes the first 100 user records.

Program Solution Hints/Suggestions:
First you need to create three groups, faculty, staff, and student before you create user accounts in your system.
• Group “student” will include all the users with status field value of ‘freshman’, ‘sophomore’, ‘junior, or ‘senior’.
• Group “staff” will include all the users with status field value of ‘staff’ and
• Group “faculty” will include all the users with status field value of ‘faculty’.

Secondly, you create a user account based on the format below for his/her login name and password:
1. Username (login name): [first initial][last name][last two digits of the user ID]
Example: John Smith, ID# 123-45-6789, would have a username of jsmith89
- make sure it is all lower-case since Linux is case-sensitive.
2. Password: user’s password is the user’s 8-digit birth date (MMDDYYYY, without the dashes.)
Example: John Smith, born on Feb. 8th, 1981, would have a password of 02081981
Lastly, you set the user to the appropriate Group (either student, staff, or faculty).

and here is the source code he provided..general idea i get is to read the lines from txt file...my classmate says we run the .exe file of that code to command line on windows ( which i am confused how to)...

//addDeleteUsersWinSp10.cpp
#include <iostream>
#include <string>
using namespace std;

int main(int argc, char* args[])
{
string command;

//system("ipconfig");

//command = "ipconfig /all";
//system(command.c_str());
cout << "argc: " << argc << endl;
for(int i = 0; i < argc; i++)
cout << args[i] << endl;
cout << endl;

command = "net group group000 /add";
system(command.c_str());

command = "net user john000 password-01 /add";
system(command.c_str());

command = "net group group000 john000 /add";
system(command.c_str());

return 0;
}
just some hints would be really appreciated....
closed account (S6k9GNh0)
Don't use C++? Use of system like this is atrocious. If someone were a professional programmer and turned this into me, I would smack the silly out of that someone.
Last edited on
lol...thats funny but didnt help me...i am already behind due date...somebody please help me...so far i have written this code to actually store each of 160 lines from txt file to array of string ...now i want each string to break it up into more arrays because each line is in format of:
Patrik:Queiroz:02-03-1975:senior:100-10-4827:c
and iwant to break it up six more array of character so i can use a loop afterwards to compare the string and designate the user to appropriate group and give password etc...

here is my code so far
#include <iostream>
#include <string>
#include<fstream>
using namespace std;

int main(int argc, char* args[])
{
string userinfo[160]; // creates array to hold names

short loop=0; //short for loop for input


string line; //this will contain the data read from the file
ifstream myfile ("F:\\users100.txt"); //opening the file.
if (myfile.is_open()) //if the file is open
{
while (! myfile.eof() ) //while the end of file is NOT reached
{
getline (myfile,line); //get one line from the file
userinfo[loop] = line;


loop++;
}

for(int i=0;i<160;i++)
{
cout<<userinfo[i]<<endl;

}


return 0;
}
}
closed account (o1vk4iN6)
I'd personally just create a batch script to do this, which is basically what you are using system for anyways.

Otherwise just search microsoft's libraries http://msdn.microsoft.com/en-us/library/windows/desktop/aa370649(v=vs.85).aspx
Last edited on
thanks xerzi but that looks even more complicated to me....i am struggling with win32 api already...
Topic archived. No new replies allowed.