WnetAddConnection2 怎么用谁能给个例子(100分)

  • 主题发起人 主题发起人 dlink
  • 开始时间 开始时间
D

dlink

Unregistered / Unconfirmed
GUEST, unregistred user!
WnetAddConnection2
 
var<br>&nbsp; NR: NETRESOURCE;<br>&nbsp; Ret: DWORD;<br>&nbsp; S: string;<br>begin<br>&nbsp; S := '//remotemachine';<br>&nbsp; NR.dwType := RESOURCETYPE_ANY;<br>&nbsp; NR.lpLocalName := nil;<br>&nbsp; NR.lpRemoteName := PChar(S);<br>&nbsp; NR.lpProvider := nil;<br>&nbsp; Ret := WNetAddConnection2(NR,PChar(edtPwd.Text),PChar(edtUser.Text),CONNECT_UPDATE_PROFILE);<br>&nbsp; if Ret &lt;&gt; NO_ERROR then<br>&nbsp; begin<br>&nbsp; &nbsp; if Ret &lt;&gt; ERROR_EXTENDED_ERROR then RaiseLastWin32Error<br>&nbsp; &nbsp; else CallNetExtError;<br>&nbsp; end<br>&nbsp; else begin<br>&nbsp; &nbsp; Application.MessageBox('Login OK! ^_^','提示',MB_OK or MB_ICONINFORMATION);<br>&nbsp; end;<br>end;<br><br>procedure CallNetExtError;<br>var<br>&nbsp; ErrorCode: Cardinal;<br>&nbsp; ErrBuf,NameBuf: string;<br>&nbsp; ShowMsg: string;<br>begin<br>&nbsp; SetLength(ErrBuf,MAX_PATH);<br>&nbsp; SetLength(NameBuf,MAX_PATH);<br>&nbsp; if WNetGetLastError(ErrorCode,PChar(ErrBuf),MAX_PATH+1,PChar(NameBuf),MAX_PATH+1) = NO_ERROR then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMsg := 'Error Code:' + IntToStr(ErrorCode) + #13#10;<br>&nbsp; &nbsp; ShowMsg := ShowMsg + 'Error String:' + ErrBuf + #13#10;<br>&nbsp; &nbsp; ShowMsg := ShowMsg + 'Error Provider:' + NameBuf;<br>&nbsp; &nbsp; ShowMessage(ShowMsg);<br>&nbsp; end<br>&nbsp; else ShowMessage('Invalid Buffer Size! :-(');<br>end;
 
var<br>&nbsp; NRW: TNetResource;<br><br><br>&nbsp; lcServerPath := Trim(lcServerPath);<br>&nbsp; lcPws := Trim(lcPws)<br>&nbsp; NRW.dwType := RESOURCETYPE_ANY;<br>&nbsp; NRW.lpLocalName :='';<br>&nbsp; NRW.lpRemoteName:= pchar(lcServerPath);<br>&nbsp; NRW.lpProvider := '';<br>&nbsp; lnReturn := WNetAddConnection2(NRW, pchar(lcPws),'guest',CONNECT_UPDATE_PROFILE);
 
接受答案了.
 
后退
顶部