Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Windows Security Network Credentials Login Prompt

Windows Security Network Credentials Login Prompt

Windows Security Network Credentials Login Prompt


I have a code in a module that with open a password protected sharefolder which will prompt a popup.
Windows Security
Enter Network Credentials

The code work fine.


'connect to password protected sharefolder
Shell "C:\WINDOWS\explorer.exe """ & strPath & "", vbHide 

This will not put the login prompt in focus at the Access application view. If I use vbNormalFocus, it will show both the Login prompt and Explorer window.

Is there a better way to hide the Explorer window and only show the Login prompt in Focus?

I have tried searching but there were only codes to hide Explorer window. None of the code could put the login prompt in Focus. I couldn't find any code that will put the Login prompt in focus.

Sample of the code below, it doesn't put the login prompt on focus.


Sub fRunTest()
    Dim PID As Long
    Dim Ret As String, strUNC As String, WinWnd As Long
    strUNC = "\\MyComputer\MyShareFolder\"
    PID = Shell("c:\windows\explorer.exe """ & strUNC & "", vbNormalFocus)
    If PID = 0 Then MsgBox "Error starting the app"
    'retrieve the handle of the window
    mWnd = InstanceToWnd(PID)
    'Set the exe parent
    SetParent mWnd, hWndAccessApp  
    'Put the focus on exe
    Putfocus mWnd
    ShowWindow mWnd, SW_HIDE   'hide explorer
End Sub

Function InstanceToWnd(ByVal target_pid As Long) As Long
    Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
    'Find the first window
    'test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
    test_hwnd = FindWindowAny("Credential Dialog Xaml Host", "Windows Security")
    Do While test_hwnd <> 0
        'Check if the window isn't a child
        If GetParent(test_hwnd) = 0 Then
            'Get the window's thread
            test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
            If test_pid = target_pid Then
                InstanceToWnd = test_hwnd
                Exit Do
            End If
        End If
        'retrieve the next window
        test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
End Function 

RE: Windows Security Network Credentials Login Prompt


Still didn't work. I need to hide the Explorer and set the "Windows Security" login in focus.

Or is there anyway to just popup the "Windows Security" Login Credentials without the Explorer?

RE: Windows Security Network Credentials Login Prompt


Ok.....found out why it won't work. Below is a code that will work.

CODE --> vba

Shell "c:\windows\explorer.exe " & strUNC , vbHide   'link to share folder and hide explorer window.
Pause 3    'pause timer  - set focus after 3 sec delay.
AppActivate "Windows Security" 

A delay is required, as the Login popup takes time to instance the object. A fast computer, you can set to 1 second. On a slow computer is between 3 to 6 seconds.

MyAppID or PID won't work in this case as the window is "File Explorer". A name for the window is require. Can't find a way to ID the "Windows Security" instance from "Function InstanceToWnd(ByVal target_pid As Long) As Long"

Well, maybe I'll try using "AppActivate test_hwnd" instead of a function later.
"test_hwnd = FindWindow("Credential Dialog Xaml Host", "Windows Security")"

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close