C + + execution cmd command using the system function, successful execution, function return value is 0, failure return value is not 0 value.
If the disk is mapped and mapped again, the error is thrown, so you need to remove the disk mappings before the program exits.
Disk Mapping command:
NET use Z: "ServerURL" "/user:serveruser" Serverpassword
Z: A space is required behind
To delete a disk mapping command:
NET use Z:/del/yes
The parameter of the system function is a const char * type
If the argument to pass a command string in a program is a CString type, you need to convert the CString type to a const char * type
If in VC + + environment, the character set is Unicode, the CString type is converted to the const char * type as follows:
CString strcommend = _t ("net use Z: \" serverurl\ "\"/user:serveruser\ "Serverpassword"); The quotes in quotes need to be escaped
Char strparam[256] = {0};
Wcstombs (Strparam, Strcommend, Strcommend.getlength ());
const char * pcommend = strparam;
int ret = System (Pcommend);
if (0 = ret)
return TRUE;
Else
return FALSE;