2017-07-17 129 views
3

我有一个应用程序有时会访问本地网络中的文件共享。 在这种情况下,路径存储在fEBookPath中。 如果用户输入登录名和密码,那么以前一切都很好。但是,如果不FindFirst不返回0.在这种情况下,我想显示Windows资源管理器显示相同的安全对话框。 像这样如何显示Windows安全对话框

enter image description here

我的简化代码

if FindFirst(fEBookPath + '*.*', faDirectory, vSearchRecFolder) = 0 then 
begin 
    // Existing code to access fEBookPath 
end 
else 
    // Display Windows security dialog to enter login + password 
+4

[WNetAddConnection2(https://msdn.microsoft.com/en -us/library/windows/desktop/aa385413(v = vs.85).aspx)+ CONNECT_PROMPT将提示并设置连接。 –

+1

您正在连接到网络资源,而不是显示对话框。结果类型是'DWORD',你可能不想连接到打印机,但是磁盘。而那些空的字符串,你可以简单地'空'。 – Victoria

+0

好的,谢谢你的建议 –

回答

2

此代码应该做我想做的

function TLogonForm.ShowSecurity: DWORD; 
var 
    UNCPath,UserName,PassWord: string; 
    NwR : TNetResource; 
begin 
    UNCPath := '\\xenapp06'; 
    NwR.lpLocalName:= ''; 
    NwR.lpProvider := ''; 
    NwR.dwType  := RESOURCETYPE_DISK; 
    NwR.lpRemoteName:= PChar(UNCPath); 
    Result := WNetAddConnection2(NwR, nil, nil, CONNECT_INTERACTIVE or CONNECT_PROMPT); 
end;