如何显示Windows登录表单纯粹是为了在VB6中验证用户帐户?

时间:2012-06-22 19:33:50

标签: windows vb6

我们有一个旧的 VB6 应用程序,曾经在各种用户的帐户下运行。我们不得不将其移至“公共”机器,其中多个用户使用相同的帐户,该帐户会自动登录。

有没有办法弹出官方的Windows身份验证表单,让用户输入他们的凭据并将状态天气或状态天气传回给我?

我可以让用户输入他们的用户名/密码到我自己创建的表单中,并使用附加的代码来验证身份验证。问题是,这开始时看起来很粗略,我宁愿不能访问用户密码。

以下是我可以用来验证用户身份的代码:

on error resume next
strUserName = "username"
strPassword = "password"
strADsPath = "WinNT://domainname"
iFlags = "0"

' bind to the ADSI object and authenticate Username and password 
Set oADsObject = GetObject(strADsPath)
strADsNamespace = left(strADsPath, instr(strADsPath, ":"))

set oADsNamespace = GetObject(strADsNamespace)
Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, "domainname\" & strUserName, strPassword, 0)

If not (Err.number = 0) Then
    MsgBox(strUserName + " Failed.")
Else
    MsgBox(strUserName + " Authenticated.")
End If

我希望有类似的东西:

if (AuthenticateUser() <> true)
    MsgBox(strUserName + " Failed.")
Else
    MsgBox(strUserName + " Authenticated.")
End If

1 个答案:

答案 0 :(得分:2)

您可以尝试使用ShellExecute()"runas"动词/操作运行主要的小型存根可执行文件。这应该导致Windows提示输入用户名/密码。这可能会限制他们与其他应用程序交互的访问权限。