?
Solved

Check NT Logon Credentials from Excel

Posted on 2003-03-20
10
Medium Priority
?
407 Views
Last Modified: 2012-08-14
I would like to prompt the user to input his current NT password and check those credentials before allowing access to the spreadsheet. i.e. I only want it used on machines where the user is authenticated to the domain.

I can check the Current User Name so will pre-populate the logon box with that.

Alternativly is there another way?
Could I call the NT logon (returning an error if it's not an NT box) and a True/False flag for the authentication?

Or can anyone think of a better way of acomplishing this.......probably :-)

Cheers

Rob


0
Comment
Question by:RobHJ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 2

Expert Comment

by:saurabhgupta
ID: 8175215
Hi cMh,
Use the Execute method method to make asynchronous call
Inet1.Execute URL, "GET"

Private Sub Inet1_StateChanged(ByVal State As Integer)
    Select Case State
    Case icResponseCompleted
    On Error Resume Next
    Dim tmpData As String
    tmpData = Inet1.GetChunk(1024, icString)
    While Len(tmpData) <> 0
        DoEvents
        HTML = HTML + tmpData
        tmpData = Inet1.GetChunk(1024, icString)
    Wend
    Me.Hide
    Case icError
    End Select
End Sub

Regards
Saurabh
0
 
LVL 2

Expert Comment

by:saurabhgupta
ID: 8175246
Sorry, posted it in the wrong place :p
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8176967
I don't understand what you really need but to know who is the logon user, you could use:
environ("username"
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8177083
to know other values:
Private Sub Form_Load()
Do
    i = i + 1
    tmp = Environ(i)
    Debug.Print i; tmp
   
Loop Until tmp = ""
End Sub
0
 

Author Comment

by:RobHJ
ID: 8177382
This gets me the various environment variables but i need to prompt the user to "Logon" and compare the response with the values in registry (User Name, Password, Domain). This is to ensure that the spreadsheet cannot (trivially) be used off site.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8180645
Well, in the case that you could show the NT logon window.. how do you go to get what the user types?
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 500 total points
ID: 8180697
Take a chance on this. Take in mind that USER_INFO_3 type has all the values that you need.
You have to collect the data from the user by yourself so change the code at form load accordingly.

Const NERR_Success = 0
Private Const NERR_BASE = 2100
Private Const NERR_InvalidComputer = (NERR_BASE + 251)
Private Const NERR_UseNotFound = (NERR_BASE + 150)
Const CP_ACP = 0
Private Type USER_INFO_3
    usri3_name As Long
    usri3_password As Long
    usri3_password_age As Long
    usri3_priv As Long
    usri3_home_dir As Long
    usri3_comment As Long
    usri3_flags As Long
    usri3_script_path As Long
    usri3_auth_flags As Long
    usri3_full_name As Long
    usri3_usr_comment As Long
    usri3_parms As Long
    usri3_workstations As Long
    usri3_last_logon As Long
    usri3_last_logoff As Long
    usri3_acct_expires As Long
    usri3_max_storage As Long
    usri3_units_per_week As Long
    usri3_logon_hours As Byte
    usri3_bad_pw_count As Long
    usri3_num_logons As Long
    usri3_logon_server As String
    usri3_country_code As Long
    usri3_code_page As Long
    usri3_user_id As Long
    usri3_primary_group_id As Long
    usri3_profile As Long
    usri3_home_dir_drive As Long
    usri3_password_expired As Long
End Type
Private Declare Function NetUserGetInfo Lib "netapi32" (lpServer As Any, UserName As Byte, ByVal Level As Long, lpBuffer As Long) As Long
Private Declare Function NetApiBufferFree Lib "netapi32" (ByVal Buffer As Long) As Long
Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)
Private Declare Function lstrlenW Lib "kernel32" (lpString As Any) As Long
Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal codepage As Long, ByVal dwFlags As Long, lpWideCharStr As Any, ByVal cchWideChar As Long, lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long
' Returns an ANSI string from a pointer to a Unicode string.
Public Function GetStrFromPtrW(lpszW As Long) As String
    Dim sRtn As String
    sRtn = String$(lstrlenW(ByVal lpszW) * 2, 0)   ' 2 bytes/char
    ' WideCharToMultiByte also returns Unicode string length
    Call WideCharToMultiByte(CP_ACP, 0, ByVal lpszW, -1, ByVal sRtn, Len(sRtn), 0, 0)
    GetStrFromPtrW = GetStrFromBufferA(sRtn)
End Function
' Returns the string before first null char encountered (if any) from an ANSII string.
Public Function GetStrFromBufferA(sz As String) As String
    If InStr(sz, vbNullChar) Then
        GetStrFromBufferA = Left$(sz, InStr(sz, vbNullChar) - 1)
    Else
        ' If sz had no null char, the Left$ function
        ' above would return a zero length string ("").
        GetStrFromBufferA = sz
    End If
End Function
Private Sub Form_Load()
    'KPD-Team 2001
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim lpBuf As Long
    Dim ui3 As USER_INFO_3
    ' replace "Administrator" with a valid NT username
    Dim bServer() As Byte, bUsername() As Byte
    bServer = "" & vbNullChar
    bUsername = "Administrator" & vbNullChar
    If (NetUserGetInfo(bServer(0), bUsername(0), 3, lpBuf) = NERR_Success) Then
        Call MoveMemory(ui3, ByVal lpBuf, Len(ui3))
        MsgBox GetStrFromPtrW(ui3.usri3_name)
        MsgBox GetStrFromPtrW(ui3.usri3_comment)
        Call NetApiBufferFree(ByVal lpBuf)
    End If
End Sub
0
 

Expert Comment

by:CleanupPing
ID: 8531928
Hi RobHJ,
This old question (QID 20557644) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8982608
This question has been classified as abandoned.  I will make a recommendation to the moderators on its resolution in a week or two.  I would appreciate any comments by the experts that would help me in making a recommendation.
It is assumed that any participant not responding to this request is no longer interested in its final deposition.

If the asker does not know how to close the question, the options are here:
http://www.experts-exchange.com/help/closing.jsp

GPrentice00
Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question