How to open "Enter Network Credentials" in Windows 10

1

I'm using the Windows Shell API to access Network machines and their folders.

shellFolder.EnumObjects(hwnd, grfFlags, out enumIdList);

....

int result = shellEnum.Next(celt, out itemPidl, out numFetched);

I'm using the IShellFolder.EnumObjects() method, which works great and I can get a list of machines in my Network.

However, when I try to get folders from these networks, it works only when there is no need of authentication to the machine. If there is a need of authentication, the method returns 0x80004005 (E_FAIL).

Windows File Explorer shows a prompt to "Enter Network Credentials" for these machines. How can I show the same prompt from my WPF program and continue based on user's credentials?

c#
.net
shell
winapi
windows-shell
asked on Stack Overflow Oct 6, 2020 by Chuck Norris • edited Oct 7, 2020 by Remy Lebeau

1 Answer

1

In most of the Shell API, a HWND handle can be passed, but it's optional, and it's also a way to say "disable UI".

This is the case for the IShellFolder::EnumObjects method

HRESULT EnumObjects(HWND hwnd, SHCONTF grfFlags, IEnumIDList **ppenumIDList);

hwnd parameter official documentation:

If user input is required to perform the enumeration, this window handle should be used by the enumeration object as the parent window to take user input. An example would be a dialog box to ask for a password or prompt the user to insert a CD or floppy disk. If hwndOwner is set to NULL, the enumerator should not post any messages, and if user input is required, it should silently fail.

answered on Stack Overflow Oct 9, 2020 by Simon Mourier

User contributions licensed under CC BY-SA 3.0