局域网的连接问题(30分)(30分)

  • 主题发起人 主题发起人 youxi
  • 开始时间 开始时间
Y

youxi

Unregistered / Unconfirmed
GUEST, unregistred user!
我想在局域网中传输数据,但是机器上有密码,哪位DX能告诉我怎么样用语句来解决这个问题。例如:局域网中有A,B两个机器,B的登陆名是aaa,密码是bbb,A这样用语句实现与B的连接,而不弹出要求输入网络密码的对话框。谢谢!!
 
一个简单的办法就是你自己写一个小程序代替Windows的映射。。

function ConnectDrive(_drvLetter: string; _netPath: string; _showError: Boolean;
_reconnect: Boolean): DWORD;
var
nRes: TNetResource;
errCode: DWORD;
dwFlags: DWORD;
begin
{ Fill NetRessource with #0 to provide uninitialized values }
FillChar(NRes, SizeOf(NRes), #0);
nRes.dwType := RESOURCETYPE_DISK;
{ Set Driveletter and Networkpath }
nRes.lpLocalName := PChar(_drvLetter);
nRes.lpRemoteName := PChar(_netPath); { Example: //Test/C }
{ Check if it should be saved for use after restart and set flags }
if _reconnect then
dwFlags := CONNECT_UPDATE_PROFILE and CONNECT_INTERACTIVE
else
dwFlags := CONNECT_INTERACTIVE;

errCode := WNetAddConnection3(Form1.Handle, nRes, nil, nil, dwFlags);
{ Show Errormessage, if flag is set }
if (errCode <> NO_ERROR) and (_showError) then
begin
Application.MessageBox(PChar('An error occured while connecting:' + #13#10 +
SysErrorMessage(GetLastError)),
'Error while connecting!',
MB_OK);
end;
Result := errCode; { NO_ERROR }
end;


function DisconnectNetDrive(_locDrive: string; _showError: Boolean; _force: Boolean;
_save: Boolean): DWORD;
var
dwFlags: DWORD;
errCode: DWORD;
begin
{ Set dwFlags, if necessary }
{ Setze dwFlags auf gewünschten Wert }
if _save then
dwFlags := CONNECT_UPDATE_PROFILE
else
dwFlags := 0;

{ Cancel the connection see also at http://www.swissdelphicenter.ch/en/showcode.php?id=391 }
errCode := WNetCancelConnection2(PChar(_locDrive), dwFlags, _force);

{ Show Errormessage, if flag is set }
if (errCode <> NO_ERROR) and (_showError) then
begin
Application.MessageBox(PChar('An error occured while disconnecting:' + #13#10 +
SysErrorMessage(GetLastError)),
'Error while disconnecting',
MB_OK);
end;
Result := errCode; { NO_ERROR }
end;


{映射网络驱动器}
procedure TForm1.Button1Click(Sender: TObject);
begin
ConnectDrive('O:', '//SERVER/C$', True, True);
end;

{断开网络驱动器}
procedure TForm1.Button2Click(Sender: TObject);
begin
DisconnectNetDrive('M:', True, True, True);
end;


另外:tcp方式不要密码
 
好象不行!
 
最简单的可用下列语句:
netstr:='net use // b bbb /user:aaa';
WinExec(Pchar(netstr),sw_hide);
有一点不好,用户名或密码更改不出现错误提示
 
多人接受答案了。
 
后退
顶部