How to display the Windows security dialog

I have an application that sometimes accesses file files on a local network. In this case, the path is stored in fEBookPath. If the user enters a username and password, as before that everything is fine. But if not FindFirst does not return 0. In this case, I want to display the same security dialog as Windows Explorer. Like this

enter image description here

My simplified code

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

      

+3


source to share


1 answer


This code should do what I want



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;

      

+2


source







All Articles