0

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?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Ertzel
1

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());
0

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.

Edited by Ertzel: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.