Hi all,
How can I show the windows authentication screen thorugh vb coding ?. Is it possible ?
Dana
Printable View
Hi all,
How can I show the windows authentication screen thorugh vb coding ?. Is it possible ?
Dana
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?
I dont think its the logon screen but maybe the activation screen? Or perhaps the About form?
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
Dana,Make use of API.
There is an API to connect the network drive,wnetaddconnection2.
I think this will be useful for u,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
If this connection fails means u can display the login form..
Try this, a sample below..
:thumb: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
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 ?
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.
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
whats the title of the dialoq box
The titile of the dialog box is "Connect to XXXXX"
Display Properties dialog box Resources on TechRepublic
i think this might be useful for u..
here
Some good infos.But Not I wanted :rolleyes:
Yes I found it :)
MSDNCode:ErrInfo = WNetAddConnection2(NetR, MyPass, MyUser, _
CONNECT_INTERACTIVE Or CONNECT_PROMPT)
:wave:
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
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?
The code I am using is
vb Code:
Option Explicit Private m_WindowsUserName As String Private m_NetworkPath As String Private ErrInfo As Long 'Initialization of Varraibles 'Private Sub Class_Initialize() ' MapDrive 'End Sub Private Function MapDrive() Dim NetR As NETRESOURCE Dim MyPass As String, MyUser As String 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 ) If ErrInfo = NO_ERROR Then MsgBox "Net Connection Successful!", vbExclamation, "Share Connected" Else MsgBox GetErrorInfo, vbExclamation, "Share Not Connected" End If End Function 'Function get the Error description using Error Id Private Function GetErrorInfo() As String If ErrInfo = NO_ERROR Then 'If no Error do nothing ElseIf ErrInfo = ERROR_CANCELLED Then GetErrorInfo = "User Cancelled !" ElseIf ErrInfo = ERROR_NO_NET_OR_BAD_PATH Then GetErrorInfo = "Network Not Found !" ElseIf ErrInfo = ERROR_NO_NETWORK Then GetErrorInfo = "Network Not Found !" ElseIf ErrInfo = ERROR_DEVICE_ALREADY_REMEMBERED Then GetErrorInfo = "The Network is Already Connect. Please disconnect it and try again !" Else GetErrorInfo = ErrInfo & " - Net Connection Failed!" End If If Len(GetErrorInfo) > 0 Then GetErrorInfo = "ERROR : " & GetErrorInfo End If End Function Public Property Get NetWorkPath() As String NetWorkPath = m_NetworkPath End Property Public Property Let NetWorkPath(ByVal vNewValue As String) m_NetworkPath = vNewValue End Property Public Function MapRemoteDrive() MapDrive End Function
Yes Mr.Rob. I am passing the correct servername only.I have posted the code there :)
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"]VBNullstring, VBNullstring,[/COLOR] _
CONNECT_INTERACTIVE Or CONNECT_PROMPT)
Looks ok but what its the return value?
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 ?
http://www.vbforums.com/
Dana
What if you take the CONNECT_PROMPT out?
I tried this code
It returned the value 0 for one server which I have rightsCode: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
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
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
It Returns the values as "The Operation Complelted Successfully" and then I tryied to click the Drive, giving msg that Access is denied ?
Hmm, not sure what else it could be other then it not retaining the username/password or its using a different set.