Results 1 to 26 of 26

Thread: Showing Windows Authentication Screen

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Smile Showing Windows Authentication Screen

    Hi all,
    How can I show the windows authentication screen thorugh vb coding ?. Is it possible ?

    Dana
    Please mark you thread resolved using the Thread Tools as shown

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Showing Windows Authentication Screen

    Are you talking about the Windows login screen?

    If so, that will be displayed only after someone is logged out and someone else wants to log in.

    You could replicate it with your own VB form though.

    Why do you need to display this?

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Showing Windows Authentication Screen

    I dont think its the logon screen but maybe the activation screen? Or perhaps the About form?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Showing Windows Authentication Screen

    Thanks Rob and Hack

    Basically the need is , I want to map a network drive. If the user has access to that
    site then that path will map automatically. If the user doesnt have any rights
    the i need to get the username and pwd from the user by using windows authentication screen. Is it possible.

    Dana
    Please mark you thread resolved using the Thread Tools as shown

  5. #5
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Showing Windows Authentication Screen

    Dana,Make use of API.
    There is an API to connect the network drive,wnetaddconnection2.

    Code:
    Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
    I think this will be useful for u,
    If this connection fails means u can display the login form..
    Try this, a sample below..

    Code:
    Private Sub Command14_Click()
        Dim l As Long, username As String, userpassword As String, result As Long
        theNetResource.lpRemoteName = "XXXXXXXX"
        theNetResource.lpLocalName = "X:"
        username = "xxxxxxx"
        userpassword = "xxxxxxx"
        theNetResource.dwType = RESOURCETYPE_DISK
        result = WNetAddConnection2(theNetResource, userpassword, username, 0)
        End Sub
    Last edited by vijy; Dec 4th, 2007 at 11:40 PM.
    Visual Studio.net 2010
    If this post is useful, rate it


  6. #6

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Showing Windows Authentication Screen

    Thanks for the info Vijy,
    But How to check whether the user has rights to the particular server.If the user has the rights
    it should be automatically mapped else, I have to get show the authentication screen of windows and get the password ?
    Please mark you thread resolved using the Thread Tools as shown

  7. #7
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Showing Windows Authentication Screen

    Are u maintaining any database for those user who haing rights??

    Dana, in Mycomputer-> manage-> groups u will have the details about what all the rights u having in ur local.

    Like this u can trap the server to see who all the users having rights and those details..
    From that information u can match the user name.But for this u have the admin rights for the server.
    Visual Studio.net 2010
    If this post is useful, rate it


  8. #8

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Showing Windows Authentication Screen

    Yes. I can able to get the username from the current computer and verify that name in the server. But How to show the
    Dialog box.That is the main question.Is there any Api avalible.I found that WNetConnectionDialog show the mapnetwork dialog.
    Like that is there any api ? For example if you open an IE explorer and type the servername which you dont have access
    you will be shown a dialog box for getting the Username and pwd ?

    Dana
    Please mark you thread resolved using the Thread Tools as shown

  9. #9
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Showing Windows Authentication Screen

    whats the title of the dialoq box
    Visual Studio.net 2010
    If this post is useful, rate it


  10. #10

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Showing Windows Authentication Screen

    The titile of the dialog box is "Connect to XXXXX"
    Please mark you thread resolved using the Thread Tools as shown

  11. #11
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Showing Windows Authentication Screen

    Display Properties dialog box Resources on TechRepublic
    i think this might be useful for u..
    here
    Visual Studio.net 2010
    If this post is useful, rate it


  12. #12

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Showing Windows Authentication Screen

    Some good infos.But Not I wanted
    Please mark you thread resolved using the Thread Tools as shown

  13. #13

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Showing Windows Authentication Screen

    Yes I found it
    Code:
     ErrInfo = WNetAddConnection2(NetR, MyPass, MyUser, _
          CONNECT_INTERACTIVE Or CONNECT_PROMPT)
    MSDN
    Last edited by danasegarane; Dec 5th, 2007 at 05:00 AM. Reason: MSDN Link Added
    Please mark you thread resolved using the Thread Tools as shown

  14. #14
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Showing Windows Authentication Screen

    Visual Studio.net 2010
    If this post is useful, rate it


  15. #15

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Showing Windows Authentication Screen

    But Now I am facing one problem.Even If i have permision to that server it still prompting for username and password .I dont wy.Can some one help ?

    Dana
    Please mark you thread resolved using the Thread Tools as shown

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Showing Windows Authentication Screen

    Oh so you wanted to show a logon form for authentication to other resources. Are you passing the correct server name \ username so that the credientials are per domain vs per machine? Also, are you passing credientials that have permissions to the resource?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Showing Windows Authentication Screen

    The code I am using is

    vb Code:
    1. Option Explicit
    2. Private m_WindowsUserName As String
    3. Private m_NetworkPath As String
    4. Private ErrInfo As Long
    5. 'Initialization of Varraibles
    6. 'Private Sub Class_Initialize()
    7. '   MapDrive
    8. 'End Sub
    9.  
    10. Private Function MapDrive()
    11.     Dim NetR As NETRESOURCE
    12.     Dim MyPass As String, MyUser As String
    13.     NetR.dwScope = RESOURCE_GLOBALNET
    14.     NetR.dwType = RESOURCETYPE_DISK
    15.     NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
    16.     NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
    17.     NetR.lpLocalName = "X:" ' If undefined, Connect with no device
    18.     NetR.lpRemoteName = m_NetworkPath    ' Your valid share
    19.     ' If the MyPass and MyUser arguments are null (use vbNullString), the
    20.     ' user context for the process provides the default user name.
    21.     ErrInfo = WNetAddConnection2(NetR, MyPass, MyUser, _
    22.    CONNECT_INTERACTIVE Or CONNECT_PROMPT)
    23.     'CONNECT_INTERACTIVE )
    24.     If ErrInfo = NO_ERROR Then
    25.         MsgBox "Net Connection Successful!", vbExclamation, "Share Connected"
    26.     Else
    27.         MsgBox GetErrorInfo, vbExclamation, "Share Not Connected"
    28.     End If
    29. End Function
    30.  
    31. 'Function get the Error description using Error Id
    32. Private Function GetErrorInfo() As String
    33.     If ErrInfo = NO_ERROR Then
    34.     'If no Error do nothing
    35.     ElseIf ErrInfo = ERROR_CANCELLED Then
    36.         GetErrorInfo = "User Cancelled !"
    37.     ElseIf ErrInfo = ERROR_NO_NET_OR_BAD_PATH Then
    38.         GetErrorInfo = "Network Not Found !"
    39.     ElseIf ErrInfo = ERROR_NO_NETWORK Then
    40.         GetErrorInfo = "Network Not Found !"
    41.     ElseIf ErrInfo = ERROR_DEVICE_ALREADY_REMEMBERED Then
    42.         GetErrorInfo = "The Network is Already Connect. Please disconnect it and try again !"
    43.     Else
    44.         GetErrorInfo = ErrInfo & " - Net Connection Failed!"
    45.     End If
    46.     If Len(GetErrorInfo) > 0 Then
    47.     GetErrorInfo = "ERROR : " & GetErrorInfo
    48.     End If
    49. End Function
    50.  
    51. Public Property Get NetWorkPath() As String
    52.     NetWorkPath = m_NetworkPath
    53. End Property
    54.  
    55. Public Property Let NetWorkPath(ByVal vNewValue As String)
    56.     m_NetworkPath = vNewValue
    57. End Property
    58.  
    59. Public Function MapRemoteDrive()
    60.     MapDrive
    61. End Function
    Please mark you thread resolved using the Thread Tools as shown

  18. #18

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Showing Windows Authentication Screen

    Yes Mr.Rob. I am passing the correct servername only.I have posted the code there
    Please mark you thread resolved using the Thread Tools as shown

  19. #19

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Showing Windows Authentication Screen

    Dear Rob and Hack,
    I want to use the default username and password to map the drive.If it doesnt match, it has to dispay the
    authentication window.Is this correct ?
    PHP Code:
    ErrInfo WNetAddConnection2(NetR, [COLOR="Blue"]VBNullstringVBNullstring,[/COLOR_
       CONNECT_INTERACTIVE 
    Or CONNECT_PROMPT
    Please mark you thread resolved using the Thread Tools as shown

  20. #20
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Showing Windows Authentication Screen

    Looks ok but what its the return value?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  21. #21

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Showing Windows Authentication Screen

    Dear Rob,
    Actually when type the server name from the run command it open in the explorer.But If i open the same server then it is prompting the authentication dialog box ? .What could be reason ?



    Dana
    Please mark you thread resolved using the Thread Tools as shown

  22. #22
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Showing Windows Authentication Screen

    What if you take the CONNECT_PROMPT out?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  23. #23

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Showing Windows Authentication Screen

    I tried this code
    Code:
    Private Function MapDrive()
        Dim NetR As NETRESOURCE
        Dim MyPass As String, MyUser As String
        MyUser = GetWindowsUsername
        NetR.dwScope = RESOURCE_GLOBALNET
        NetR.dwType = RESOURCETYPE_DISK
        NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
        NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
        NetR.lpLocalName = "X:" ' If undefined, Connect with no device
        NetR.lpRemoteName = m_NetworkPath    ' Your valid share
        
        ' If the MyPass and MyUser arguments are null (use vbNullString), the
        ' user context for the process provides the default user name.
    '    ErrInfo = WNetAddConnection2(NetR, MyPass, MyUser, _
    '   CONNECT_INTERACTIVE Or CONNECT_PROMPT)
        'CONNECT_INTERACTIVE )
    '     ErrInfo = WNetAddConnection2(NetR, vbNullString, vbNullString, _
    '   CONNECT_INTERACTIVE Or CONNECT_PROMPT)
       ' MyUser = GetWindowsUsername
        ErrInfo = WNetAddConnection2(NetR, vbNullString, vbNullString, _
        CONNECT_INTERACTIVE)
        MsgBox "Return value" & ErrInfo
        If ErrInfo = NO_ERROR Then
            MsgBox "Net Connection Successful!", vbExclamation, "Share Connected"
        Else
            MsgBox GetErrorInfo, vbExclamation, "Share Not Connected"
        End If
    End Function
    It returned the value 0 for one server which I have rights
    And also 0 for the one Which I dont Have rights.But When I click that mapped drive,it is giving error msg that ACCESS DENIED

  24. #24
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Showing Windows Authentication Screen

    Instead of relying on the return value try using the GetLastError API call to get more detailed return value. It may show something different. If you dont have permissions then it should return ERROR_ACCESS_DENIED
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  25. #25

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Showing Windows Authentication Screen

    It Returns the values as "The Operation Complelted Successfully" and then I tryied to click the Drive, giving msg that Access is denied ?

  26. #26
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Showing Windows Authentication Screen

    Hmm, not sure what else it could be other then it not retaining the username/password or its using a different set.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width