局域网编程的高手们请帮帮忙呀(*_*>,马上就要交任务了,现在还。。。。。。(200分)

  • 主题发起人 主题发起人 jackalan
  • 开始时间 开始时间
J

jackalan

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么用程序来自动登陆2000下的共享文件夹呀,下面是我用的连接方法,但不行的,不知道什么地方有问题!

Function ConnectLine(strDir,UserName,Password : string) : Boolean;
var
nRes: TNetResource;
begin
result := true;
if MidBstr(strDir,2,2) = ':/' then
begin
exit;
end;
nRes.dwScope := RESOURCE_GLOBALNET;
nRes.dwType := RESOURCETYPE_ANY;
nRes.dwDisplayType := RESOURCEDISPLAYTYPE_SHARE;
nRes.dwUsage := RESOURCEUSAGE_CONNECTABLE;
nRes.lpLocalName := nil;
nRes.lpRemoteName := PChar(strDir);
nRes.lpComment := nil;
nRes.lpProvider := nil;
{f WNetAddConnection(pchar(strDir),pchar(Password),'') <> 0 then
Result := false;}
if UserName = '' then UserName := 'Guest';
if WNetAddConnection2(nRes,Pchar(Password),Pchar(UserName), CONNECT_PROMPT)=0 then
begin
Result := True;
end
else
begin
Result := False;
end;
end;
如果你知道俺感激涕零。。。。。。。。。。
 
高手们哪里去了,??????[:(]
 
太失望了[?]尽然没有一个人来回答~晕~
 
在这边测试似呼没什么问题
可是服务器权限设置上存在问题.
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StrUtils;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

function ConnectLine(strDir,UserName,Password : string; var str: string) : Boolean;

var
Form1: TForm1;

implementation

{$R *.dfm}

function ConnectLine(strDir,UserName,Password : string; var str: string) : Boolean;
var
nRes: TNetResource;
begin
result := true;
if Midstr(strDir,2,2) = ':/' then
begin
exit;
end;
nRes.dwScope := RESOURCE_GLOBALNET;
nRes.dwType := RESOURCETYPE_ANY;
nRes.dwDisplayType := RESOURCEDISPLAYTYPE_SHARE;
nRes.dwUsage := RESOURCEUSAGE_CONNECTABLE;
nRes.lpLocalName := PChar('G:');;
nRes.lpRemoteName := PChar(strDir);
nRes.lpComment := nil;
nRes.lpProvider := nil;

if UserName = '' then UserName := 'Guest';
Result := false;
case WNetAddConnection2(nRes,Pchar(Password),Pchar(UserName), CONNECT_PROMPT) of
NO_ERROR: begin Result := true; str := 'Success'; end;
ERROR_ACCESS_DENIED: str :='Access to the network resource was denied.';
ERROR_ALREADY_ASSIGNED: str := 'The local device specified by lpLocalName is already connected to a network resource.';
ERROR_BAD_DEV_TYPE: str := 'The type of local device and the type of network resource do not match.';
ERROR_BAD_DEVICE: str := 'The value specified by lpLocalName is invalid.';
ERROR_BAD_NET_NAME: str := 'The value specified by lpRemoteName is not acceptable to any network resource provider. The resource name is invalid, or the named resource cannot be located.';
ERROR_BAD_PROFILE: str := 'The user profile is in an incorrect format.';
ERROR_BAD_PROVIDER: str := 'The value specified by lpProvider does not match any provider.';
ERROR_BUSY: str := 'The router or provider is busy, possibly initializing. The caller should retry.';
ERROR_CANCELLED: str := 'The attempt to make the connection was cancelled by the user through a dialog box from one of the network resource providers, or by a called resource.';
ERROR_CANNOT_OPEN_PROFILE: str := 'The system is unable to open the user profile to process persistent connections.';
ERROR_DEVICE_ALREADY_REMEMBERED: str := 'An entry for the device specified in lpLocalName is already in the user profile.';
ERROR_EXTENDED_ERROR: str := 'A network-specific error occured. Call the WNetGetLastError function to get a description of the error.';
ERROR_INVALID_PASSWORD: str := 'The specified password is invalid.';
ERROR_NO_NET_OR_BAD_PATH: str := 'A network component has not started, or the specified name could not be handled.';
ERROR_NO_NETWORK: str := 'There is no network present.';
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
strDir, userName, password: string;
str: string;
begin
strDir := '//192.168.0.30/d$';
userName := 'guest';
password := '333';
ConnectLine(strDir, userName, password, str);
Caption := str;
end;

end.
我试了,通过,200分我没收了。
 
wlmmlw先谢谢你呀!但我想请教一下,这个连接程序如果在2000下,共享了一个文件夹,权限设置为该文件夹[red]只[/red]能有如“ABC”用户访问,那么在连接的时候怎么如何都连接不上,你不要用GUEST呀,那个我也行的。这是公司的程序,我急的恨,请帮个忙谢谢!
 
后退
顶部