检查工作组服务器的用户凭据(Check user credential against a workgroup server)

编程入门 行业动态 更新时间:2024-10-28 02:27:39
检查工作组服务器的用户凭据(Check user credential against a workgroup server)

我的应用程序将在客户端台式计算机上的LAN上使用。 在此LAN中,有一个专用的Windows 2k服务器。 没有AD。

用户必须填写服务器的用户帐户信息,以便应用程序可以使用此帐户执行一些远程操作(映射网络驱动器)

如何检查此服务器的用户凭据?

映射驱动程序时,如果用户帐户身份验证不正常,我将收到错误,但我想在尝试映射之前获取此信息。

像LogonUser API函数,但在远程计算机上工作。

谢谢,

My app will be used on LAN on a client desktop computer. In this LAN, there is one dedicated Windows 2k server. There is no AD.

The user have to fill in a server's user account informations so the app can then do some remote operations with this account (Map network drives)

How can I check the user credentials against this server?

When mapping drivers, I will have the error if the user account authentication is not ok, but I would like to have this information before trying to map.

Something like LogonUser API function, but working on a remote computer.

Thanks,

最满意答案

您可以将WNetUseConnection函数与CONNECT_INTERACTIVE和CONNECT_PROMPT标志一起使用。 这将与空的用户ID和密码参数结合使用,在您输入正确的凭据时调用凭据对话框并连接到网络资源:

procedure TForm1.Button1Click(Sender: TObject); var BufferSize: DWORD; ResultFlag: DWORD; NetResource: TNetResource; begin NetResource.dwType := RESOURCETYPE_DISK; NetResource.lpLocalName := nil; NetResource.lpRemoteName := '\\MySuperSecret\Place'; NetResource.lpProvider := nil; if WNetUseConnection(Handle, NetResource, nil, nil, CONNECT_INTERACTIVE or CONNECT_PROMPT, nil, BufferSize, ResultFlag) = NO_ERROR then ShowMessage('Connected!'); end;

要在不提示输入凭据的情况下连接到网络资源,请删除上面指定的标志,如下所示,在连接成功时应返回True,在失败时返回False。 这是参数说明:

RemoteName(字符串) - 远程网络名称 UserName(字符串) - 用于连接网络资源的用户名 密码(字符串) - 用于连接网络资源的密码

function TryConnect(const RemoteName, UserName, Password: string): Boolean; var BufferSize: DWORD; ResultFlag: DWORD; NetResource: TNetResource; begin NetResource.dwType := RESOURCETYPE_DISK; NetResource.lpLocalName := nil; NetResource.lpRemoteName := PChar(RemoteName); NetResource.lpProvider := nil; Result := WNetUseConnection(0, NetResource, PChar(UserName), PChar(Password), 0, nil, BufferSize, ResultFlag) = NO_ERROR; end;

You can use the WNetUseConnection function with CONNECT_INTERACTIVE and CONNECT_PROMPT flags. That will in combination with empty user ID and password parameters invoke the credentials dialog and connect to a network resource when you enter correct credentials:

procedure TForm1.Button1Click(Sender: TObject); var BufferSize: DWORD; ResultFlag: DWORD; NetResource: TNetResource; begin NetResource.dwType := RESOURCETYPE_DISK; NetResource.lpLocalName := nil; NetResource.lpRemoteName := '\\MySuperSecret\Place'; NetResource.lpProvider := nil; if WNetUseConnection(Handle, NetResource, nil, nil, CONNECT_INTERACTIVE or CONNECT_PROMPT, nil, BufferSize, ResultFlag) = NO_ERROR then ShowMessage('Connected!'); end;

To connect to a network resource without prompting for credentials remove the flags specified above as it's shown in the following function, which should return True, when the connection succeed, False when it fails. Here's the parameter description:

RemoteName (string) - remote network name UserName (string) - user name used to connect to a network resource Password (string) - password used to connect to a network resource

function TryConnect(const RemoteName, UserName, Password: string): Boolean; var BufferSize: DWORD; ResultFlag: DWORD; NetResource: TNetResource; begin NetResource.dwType := RESOURCETYPE_DISK; NetResource.lpLocalName := nil; NetResource.lpRemoteName := PChar(RemoteName); NetResource.lpProvider := nil; Result := WNetUseConnection(0, NetResource, PChar(UserName), PChar(Password), 0, nil, BufferSize, ResultFlag) = NO_ERROR; end;

更多推荐

本文发布于:2023-07-15 20:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1118573.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:凭据   工作组   服务器   用户   Check

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!