解决方案 »

  1.   

    WNETAddConnection()映射网络驱动器
      

  2.   

    NetUseAdd   BOOL
       EstablishNullSession(
           LPCWSTR Server,
           BOOL bEstablish
           )
       {
           LPCWSTR szIpc = L"\\IPC$";
           WCHAR RemoteResource[UNCLEN + 5 + 1]; // UNC len + \IPC$ + NULL
           DWORD cchServer;       NET_API_STATUS nas;       // 
           // do not allow NULL or empty server name
           // 
           if(Server == NULL || *Server == L'\0') {
               SetLastError(ERROR_INVALID_COMPUTERNAME);
               return FALSE;
           }       cchServer = lstrlenW( Server );       if(Server[0] != L'\\' && Server[1] != L'\\') {           // 
               // prepend slashes and NULL terminate
               // 
               RemoteResource[0] = L'\\';
               RemoteResource[1] = L'\\';
               RemoteResource[2] = L'\0';
           }
           else {
               cchServer -= 2; // drop slashes from count           RemoteResource[0] = L'\0';
           }       if(cchServer > CNLEN) {
               SetLastError(ERROR_INVALID_COMPUTERNAME);
               return FALSE;
           }       if(lstrcatW(RemoteResource, Server) == NULL) return FALSE;
           if(lstrcatW(RemoteResource, szIpc) == NULL) return FALSE;       // 
           // disconnect or connect to the resource, based on bEstablish
           // 
           if(bEstablish) {
               USE_INFO_2 ui2;           ZeroMemory(&ui2, sizeof(ui2));           ui2.ui2_local = NULL;
               ui2.ui2_remote = RemoteResource;
               ui2.ui2_asg_type = USE_IPC;
               ui2.ui2_password = ui2.ui2_username = ui2.ui2_domainname = L"";           nas = NetUseAdd(NULL, 2, (LPBYTE)&ui2, NULL);
           }
           else {
               nas = NetUseDel(NULL, RemoteResource, 0);
           }       if( nas == NERR_Success ) return TRUE; // indicate success       return FALSE;
       }