I am trying to use the Net User command from the cmd in my C++ program. I have this...

char acUserName[100];
DWORD nUserName = sizeof(acUserName);

if (GetUserName(acUserName, &nUserName)){
cout << "User Name: " << acUserName << endl;
   system("Net User");
}

This displays the User Name on the screen and then also calls the Net User function, This part works fine. What I'm having problems with is I want to use the Net User username function with the acUserName the program already gets.

The only way I can think of doing that is....

char acUserName[100];
DWORD nUserName = sizeof(acUserName);

if (GetUserName(acUserName, &nUserName)){
cout << "User Name: " << acUserName << endl;
   system("Net User " && acUserName);
}

But I get the following error "cannot convert `bool' to `const char*' for argument `1' to `int system(const char*)' "

I can't figure out how to make this work. Can anyone help me out with this please?

Recommended Answers

All 2 Replies

so you want the system call to say "Net User name"? If that's all then you can use a string and put the two parts together and then pass the whole thing to system.

string command = "Net User ";
string name;
cout << "please enter the user name: ";
cin >> name;
commmand += name;
system(command.c_str());

Ohhh I forgot about the .c_str() command. I still need it to work with the user name already found but that works using .c_str().

My code looks like this now

if (GetUserName(acUserName, &nUserName)){
   string command = "Net User ";
command += acUserName;
   system(command.c_str());
}

and everything works as needed. Thank you for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.