难道就没有一个Delph 高手吗?(急急急):怎样实现远程计算机的登录?我不映射他的磁盘。(没有服务端,不能用Winexec(pchar('net use //

  • 主题发起人 主题发起人 天宇天蓝
  • 开始时间 开始时间

天宇天蓝

Unregistered / Unconfirmed
GUEST, unregistred user!
难道就没有一个Delph 高手吗?(急急急):怎样实现远程计算机的登录?我不映射他的磁盘。(没有服务端,不能用Winexec(pchar('net use //compname 'pas'/'username'')),也就是用Delphi 建立一个IPc$会话。) (200分)<br />[:(]请教高手(急急急):怎样实现远程计算机的登录?我不映射他的磁盘。
(没有服务端,不能用Winexec(pchar('net use //compname 'pas'/'username'')),
但要实现 net use //compname 'pas'/'username')[:(]
 
具体什么功能?
可以用猫开机并传输文件的
 
能连上他的机子就行了,在 cmd 里用 net use 就能看到一个连接就可能了。
 
也就是用Delphi 建立一个IPc$会话。
 
没搞过,一般写这方面的大部分是C++的资料...
 
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
netresource:Tnetresource;
re:dword;
begin
netresource.dwScope:=RESOURCE_GLOBALNET;
netresource.dwUsage:=RESOURCEUSAGE_CONNECTABLE;
netresource.dwType:=RESOURCETYPE_DISK;
netresource.dwDisplayType:=RESOURCEDISPLAYTYPE_SERVER;
netresource.lpLocalName:='';
netresource.lpRemoteName:='//server_name';
netresource.lpProvider:='';
re:=WNetAddConnection3(
application.Handle,
netresource,
'password',
'username',
CONNECT_UPDATE_PROFILE
);
if re=NO_ERROR then
begin
showmessage('ok');
end
else begin
application.MessageBox('无法连接到服务器,请与系统管理员联系','系统提示',mb_ok);
application.Terminate;
end;
end;
 
对不起!我没有测试通过。
我有两个例子,请大家看看:
var
aa:TNetResource;
retval : longint;
begin
aa.dwScope := RESOURCE_CONNECTED;
aa.dwType := RESOURCETYPE_ANY;
aa.lpLocalName := '';
aa.lpRemoteName :=pchar(LabeledEdit1.text);//compname
aa.lpProvider := Nil;

RetVal := WNetAddConnection2(aa,pchar(LabeledEdit3.Text ),pchar(LabeledEdit2.Text ),CONNECT_PROMPT);
// showmessage(inttostr(retval));//LabeledEdit3.Text为密码,LabeledEdit2.Text密码
case RetVal of
NO_ERROR:StatusBar1.Panels[0].Text:='已连接';
ERROR_ACCESS_DENIED : StatusBar1.Panels[0].Text:='ERROR_ACCESS_DENIED';
ERROR_ALREADY_ASSIGNED: StatusBar1.Panels[0].Text:='ERROR_ALREADY_ASSIGNED';
ERROR_BAD_DEV_TYPE: StatusBar1.Panels[0].Text:='网络资源类型不匹配';
ERROR_BAD_DEVICE: StatusBar1.Panels[0].Text:='用户名不正确';
ERROR_BAD_NET_NAME:StatusBar1.Panels[0].Text:='ERROR_BAD_NET_NAME';
ERROR_BAD_PROFILE: StatusBar1.Panels[0].Text:='ERROR_BAD_PROFILE';
ERROR_CANNOT_OPEN_PROFILE: StatusBar1.Panels[0].Text:='ERROR_CANNOT_OPEN_PROFILE';
ERROR_DEVICE_ALREADY_REMEMBERED: StatusBar1.Panels[0].Text:='ERROR_DEVICE_ALREADY_REMEMBERED';
ERROR_EXTENDED_ERROR: StatusBar1.Panels[0].Text:='ERROR_EXTENDED_ERROR';
ERROR_INVALID_PASSWORD: StatusBar1.Panels[0].Text:='ERROR_INVALID_PASSWORD';
ERROR_NO_NET_OR_BAD_PATH: StatusBar1.Panels[0].Text:='ERROR_NO_NET_OR_BAD_PATH';
ERROR_NO_NETWORK: StatusBar1.Panels[0].Text:='ERROR_NO_NETWORK';
end;

end;

var ss:integer;
begin
ss:=WNetAddConnection(pchar(LabeledEdit1.Text ),
pchar(LabeledEdit3.Text ),pchar(LabeledEdit2.Text ));//同上,LabeledEdit1.Text为机器名,LabeledEdit3.Text为密码,LabeledEdit2.Text密码

case ss of
NO_ERROR:StatusBar1.Panels[0].Text:='已连接';
ERROR_ACCESS_DENIED : StatusBar1.Panels[0].Text:='ERROR_ACCESS_DENIED';
ERROR_ALREADY_ASSIGNED: StatusBar1.Panels[0].Text:='ERROR_ALREADY_ASSIGNED';
ERROR_BAD_DEV_TYPE: StatusBar1.Panels[0].Text:='网络资源类型不匹配';
ERROR_BAD_DEVICE: StatusBar1.Panels[0].Text:='用户名不正确';
ERROR_BAD_NET_NAME:StatusBar1.Panels[0].Text:='ERROR_BAD_NET_NAME';
ERROR_BAD_PROFILE: StatusBar1.Panels[0].Text:='ERROR_BAD_PROFILE';
ERROR_CANNOT_OPEN_PROFILE: StatusBar1.Panels[0].Text:='ERROR_CANNOT_OPEN_PROFILE';
ERROR_DEVICE_ALREADY_REMEMBERED: StatusBar1.Panels[0].Text:='ERROR_DEVICE_ALREADY_REMEMBERED';
ERROR_EXTENDED_ERROR: StatusBar1.Panels[0].Text:='ERROR_EXTENDED_ERROR';
ERROR_INVALID_PASSWORD: StatusBar1.Panels[0].Text:='ERROR_INVALID_PASSWORD';
ERROR_NO_NET_OR_BAD_PATH: StatusBar1.Panels[0].Text:='ERROR_NO_NET_OR_BAD_PATH';
ERROR_NO_NETWORK: StatusBar1.Panels[0].Text:='ERROR_NO_NETWORK';
end;
end;
 
我记得Delphi自身就带有这方面的例子,
请看一下Delphi安装目录下的Demos目录。
 
var
netresource:Tnetresource;
re:dword;
begin
netresource.dwScope:=RESOURCE_[red]GLOBALNET;[/red]
netresource.dwUsage:=RESOURCEUSAGE_CONNECTABLE;
netresource.dwType:=RESOURCETYPE_[gold]DISK;[/gold]
netresource.dwDisplayType:=RESOURCEDISPLAYTYPE_SERVER;
netresource.lpLocalName:='';
netresource.lpRemoteName:=[blue]'//server_name'[/blue];
netresource.lpProvider:=[purple]''[/purple];
re:=WNetAddConnection3(
application.Handle,
netresource,
[blue]'password'[/blue],
[blue]'username'[/blue],
CONNECT_UPDATE_PROFILE
);

再测试一下吧,我在WINME和2000下都试过,没有问题!!!!!!!!!!!!
 
局域网上是可以,用猫在INTERNET上是不行的,
 
不错,我试了一下,在WIN2000下没有问题,其它的我没有试.
 
自己解决。

var
aa:TNetResource;
retval : longint;
begin
aa.dwScope := RESOURCE_CONNECTED;
aa.dwType := RESOURCETYPE_ANY;
aa.lpLocalName := '';
aa.lpRemoteName :=pchar('//'+LabeledEdit1.text);//compname
aa.lpProvider := Nil;

RetVal := WNetAddConnection2(aa,pchar(LabeledEdit3.Text ),pchar(LabeledEdit2.Text ),CONNECT_PROMPT);
// showmessage(inttostr(retval));//LabeledEdit3.Text为密码,LabeledEdit2.Text密码
case RetVal of
NO_ERROR:StatusBar1.Panels[0].Text:='已连接';
ERROR_ACCESS_DENIED : StatusBar1.Panels[0].Text:='ERROR_ACCESS_DENIED';
ERROR_ALREADY_ASSIGNED: StatusBar1.Panels[0].Text:='ERROR_ALREADY_ASSIGNED';
ERROR_BAD_DEV_TYPE: StatusBar1.Panels[0].Text:='网络资源类型不匹配';
ERROR_BAD_DEVICE: StatusBar1.Panels[0].Text:='用户名不正确';
ERROR_BAD_NET_NAME:StatusBar1.Panels[0].Text:='ERROR_BAD_NET_NAME';
ERROR_BAD_PROFILE: StatusBar1.Panels[0].Text:='ERROR_BAD_PROFILE';
ERROR_CANNOT_OPEN_PROFILE: StatusBar1.Panels[0].Text:='ERROR_CANNOT_OPEN_PROFILE';
ERROR_DEVICE_ALREADY_REMEMBERED: StatusBar1.Panels[0].Text:='ERROR_DEVICE_ALREADY_REMEMBERED';
ERROR_EXTENDED_ERROR: StatusBar1.Panels[0].Text:='ERROR_EXTENDED_ERROR';
ERROR_INVALID_PASSWORD: StatusBar1.Panels[0].Text:='ERROR_INVALID_PASSWORD';
ERROR_NO_NET_OR_BAD_PATH: StatusBar1.Panels[0].Text:='ERROR_NO_NET_OR_BAD_PATH';
ERROR_NO_NETWORK: StatusBar1.Panels[0].Text:='ERROR_NO_NETWORK';
end;

end;

var ss:integer;
begin
ss:=WNetAddConnection('//'+pchar(LabeledEdit1.Text ),
pchar(LabeledEdit3.Text ),pchar(LabeledEdit2.Text ));//同上,LabeledEdit1.Text为机器名,LabeledEdit3.Text为密码,LabeledEdit2.Text密码

case ss of
NO_ERROR:StatusBar1.Panels[0].Text:='已连接';
ERROR_ACCESS_DENIED : StatusBar1.Panels[0].Text:='ERROR_ACCESS_DENIED';
ERROR_ALREADY_ASSIGNED: StatusBar1.Panels[0].Text:='ERROR_ALREADY_ASSIGNED';
ERROR_BAD_DEV_TYPE: StatusBar1.Panels[0].Text:='网络资源类型不匹配';
ERROR_BAD_DEVICE: StatusBar1.Panels[0].Text:='用户名不正确';
ERROR_BAD_NET_NAME:StatusBar1.Panels[0].Text:='ERROR_BAD_NET_NAME';
ERROR_BAD_PROFILE: StatusBar1.Panels[0].Text:='ERROR_BAD_PROFILE';
ERROR_CANNOT_OPEN_PROFILE: StatusBar1.Panels[0].Text:='ERROR_CANNOT_OPEN_PROFILE';
ERROR_DEVICE_ALREADY_REMEMBERED: StatusBar1.Panels[0].Text:='ERROR_DEVICE_ALREADY_REMEMBERED';
ERROR_EXTENDED_ERROR: StatusBar1.Panels[0].Text:='ERROR_EXTENDED_ERROR';
ERROR_INVALID_PASSWORD: StatusBar1.Panels[0].Text:='ERROR_INVALID_PASSWORD';
ERROR_NO_NET_OR_BAD_PATH: StatusBar1.Panels[0].Text:='ERROR_NO_NET_OR_BAD_PATH';
ERROR_NO_NETWORK: StatusBar1.Panels[0].Text:='ERROR_NO_NETWORK';
end;
end;
 
不过还是要谢谢heqian.
谢谢!!!
 
后退
顶部