我的应用程序将在客户端台式计算机上的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;更多推荐
发布评论