Try thisprocedure ConnectToDomain(ServerName:string); 
var 
  nr:TNetResource; 
  szRemotePath : array[0..255] of char; 
  szPassWord:array[0..255] of char; 
begin   // use default connect 
  nr.dwScope := RESOURCE_GLOBALNET; 
  nr.dwType  := RESOURCETYPE_ANY; 
  nr.dwDisplayType := RESOURCEDISPLAYTYPE_GENERIC; 
  nr.dwUsage := RESOURCEUSAGE_CONNECTABLE ; 
  nr.lpLocalName := nil; 
  nr.lpRemoteName := StrPCopy(szRemotePath,'\\'+ServerName+'\IPC$'); 
  nr.lpComment := nil; 
  nr.lpProvider:= nil; 
  if WNetAddConnection2(nr,nil,nil,0) <> NO_ERROR then begin 
    dlgLoginDomain := TdlgLoginDomain.Create(Application); 
    try 
        dlgLoginDomain.labServerName.Caption := ServerName ; 
        if dlgLoginDomain.ShowModal <> mrOK then 
          raise EPromiseAbortException.Create(''); 
        StrPCopy(szPassWord,dlgLoginDomain.Password.Text); 
        if WNetAddConnection2(nr,szPassword,nil,0) <> NO_ERROR then 
          raise EPromisePromptException.Create('Invalid password'); 
    finally 
        dlgLoginDomain.Free; 
    end; 
  end;