獲取系統帳戶密碼週期的例項

TolyHuang發表於2009-02-05

[@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部落格 ” ,連結:http://blog.itpub.net/9437124/viewspace-1016751/,如需轉載,請註明出處,否則將追究法律責任。

相關文章