Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Security Network Credentials Login Prompt

Status
Not open for further replies.

Goondu

Technical User
Jan 14, 2004
92
0
0
SG
Hi,

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.

Code:
'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.
Code:
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)
    Loop
End Function
 
Iameid,

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?
 
lameid,

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

Code:
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")"


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top