C + + disk mappings

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.