Display "Enter network credentials" if required RRS feed

  • Question

  • I have a program that uses a stored setting to access a UNC path on another server.

    If a username and password is required to access this folder, the C# program does not see it as existing.

    I am not seeking to store credentials, but instead to be able to identify this situation and to be able to have Windows display the "Windows Security" dialog to prompt to enter in the network credentials.

    Code snip:

    string Testpath = @"\\SERVER\Folder";
    // Want to check if permission issue, and prompt to enter credentials (from Windows dialog, not program)

    Thanks for any assistance.

    Friday, November 22, 2019 2:23 AM


All replies

  • Hello,

    See if the 116 reply might work for you.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    • Marked as answer by Mr Cheese Tuesday, November 26, 2019 1:41 AM
    Friday, November 22, 2019 2:51 AM
  • Network connections are global resources. Establishing a connection would open it for all processes in the same session (or in the same integrity level of the current session, if UAC is enabled), not just your process. So it is better to control it in a login script written by a server admin. If you want to isolate your network connection as much as possible, create a user dedicated for your process . 

    That said, if you want to check whether a connection to a specific network resource exist, use NetUseEnum.

    To prompt the user with the standard Windows credential dialog, use CredUIPromptForWindowsCredentials. 

    Visual C++ MVP

    Friday, November 22, 2019 2:14 PM
  • Thanks.

    The code in 116 didn't really work for me, but this was written from the previous post, 167, which I was able to start to get somewhere.

    Still have to streamline what I am wanting, but this information has started to do what I was looking for.

    Thanks for posting.

    Tuesday, November 26, 2019 1:41 AM