var<br> NR: NETRESOURCE;<br> Ret: DWORD;<br> S: string;<br>begin<br> S := '//remotemachine';<br> NR.dwType := RESOURCETYPE_ANY;<br> NR.lpLocalName := nil;<br> NR.lpRemoteName := PChar(S);<br> NR.lpProvider := nil;<br> Ret := WNetAddConnection2(NR,PChar(edtPwd.Text),PChar(edtUser.Text),CONNECT_UPDATE_PROFILE);<br> if Ret <> NO_ERROR then<br> begin<br> if Ret <> ERROR_EXTENDED_ERROR then RaiseLastWin32Error<br> else CallNetExtError;<br> end<br> else begin<br> Application.MessageBox('Login OK! ^_^','提示',MB_OK or MB_ICONINFORMATION);<br> end;<br>end;<br><br>procedure CallNetExtError;<br>var<br> ErrorCode: Cardinal;<br> ErrBuf,NameBuf: string;<br> ShowMsg: string;<br>begin<br> SetLength(ErrBuf,MAX_PATH);<br> SetLength(NameBuf,MAX_PATH);<br> if WNetGetLastError(ErrorCode,PChar(ErrBuf),MAX_PATH+1,PChar(NameBuf),MAX_PATH+1) = NO_ERROR then<br> begin<br> ShowMsg := 'Error Code:' + IntToStr(ErrorCode) + #13#10;<br> ShowMsg := ShowMsg + 'Error String:' + ErrBuf + #13#10;<br> ShowMsg := ShowMsg + 'Error Provider:' + NameBuf;<br> ShowMessage(ShowMsg);<br> end<br> else ShowMessage('Invalid Buffer Size! :-(');<br>end;