ITPub博客

首页 > IT基础架构 > 网络安全 > 获取系统帐户密码周期的实例

获取系统帐户密码周期的实例

原创 网络安全 作者:tolyhuang 时间:2009-02-05 10:08:36 0 删除 编辑

[@more@]

在界面上添加一2个lable,1个textbox,1个button.代码如下:

Option Explicit

Private Const NERR_SUCCESS As Long = 0&

Private Type USER_INFO_1
usri1_name As Long
usri1_password As Long
usri1_password_age As Long
usri1_priv As Long
usri1_home_dir As Long
usri1_comment As Long
usri1_flags As Long
usri1_script_path As Long
End Type

Private Declare Function NetUserGetInfo Lib "Netapi32" _
(Servername As Byte, _
Username As Byte, _
ByVal Level As Long, _
Buffer As Long) As Long

Private Declare Function NetApiBufferFree Lib "Netapi32" _
(ByVal Buffer As Long) As Long

Private Declare Sub CopyMemory Lib "Kernel32" _
Alias "RtlMoveMemory" _
(pTo As Any, _
uFrom As Any, _
ByVal lSize As Long)

Private Sub Form_Load()

With Label1
.Caption = "The password for"
.AutoSize = True
.Move 200, 400
End With

With Text1
.Text = "(enter a user name)"
.Move 1550, 360, 1600, 285
End With

With Label2
.Caption = "is xxxxxxx days old"
.AutoSize = True
.Move 3200, 400
End With

With Command1
.Caption = "Get Password Age"
.Move 1500, 800, 1600
End With

End Sub


Private Sub Command1_Click()

'if sServer is "" use the local machine
Label2.Caption = "is " & GetPasswordAge("", Text1.Text) & " days old"

End Sub


Private Function GetPasswordAge(sServer As String, _
sUser As String) As Single

Dim buff As Long
Dim bServer() As Byte
Dim bUser() As Byte
Dim ui1 As USER_INFO_1

bUser = sUser & vbNullChar
bServer = vbNullChar

If NetUserGetInfo(bServer(0), bUser(0), 1, buff) = NERR_SUCCESS Then

CopyMemory ui1, ByVal buff, Len(ui1)
GetPasswordAge = (ui1.usri1_password_age / 86400)

End If

NetApiBufferFree buff

End Function

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9437124/viewspace-1016751/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-07-22

  • 博文量
    268
  • 访问量
    1468744