檢驗系統帳號是否存在的例項
[@more@]
Option Explicit
Private Declare Function LookupAccountName Lib "advapi32" _
Alias "LookupAccountNameA" _
(ByVal lpSystemName As String, _
ByVal lpAccountName As String, _
Sid As Byte, _
cbSid As Long, _
ByVal DomainName As String, _
cbDomainName As Long, _
peUse As Long) As Long
Private Sub Command1_Click()
Dim sAccount As String 'account name of interest
Dim sSystem As String 'specifying the system
Dim sDomain As String 'domain validating user
Dim sValid As String
'The account name is a null-terminated
'string specifying the account name of
'interest.
sAccount = Text1.Text
'The system name is a null-terminated
'string specifying the system - this
'string can be the name of a remote computer.
'If this string is null, the account name
'is looked up on the local system.
sSystem = ""
'The domain name is a buffer where the
'call returns the name of the domain where
'the account name is found. It is not for
'specifying the domain that you want the
'lookup made on. If this parameter is passed,
'the function returns the required buffer size.
sDomain = ""
Label1.Caption = "working ..."
Label1.Refresh
Select Case ValidateUser(sAccount, sDomain, sSystem)
Case True: sValid = "User has been validated."
Case False: sValid = "User not found."
End Select
Label1.Caption = sValid
Label2.Caption = sDomain
End Sub
Public Function ValidateUser(ByRef sAccountName As String, _
Optional ByRef sDomainName As String, _
Optional ByVal sSystemName As String) As Boolean
Dim success As Long
Dim cbSid As Long
Dim cbDomainName As Long
Dim peUse As Long
Dim bSID() As Byte
sDomainName = vbNullString
cbDomainName = 0
If Len(sSystemName) = 0 Then
'If the system name (machine name)
'not specified, pass a null string
'to have the account lookup on
'the local machine
sSystemName = vbNullString
End If
'First call passes null as the SID.
'The call returns a success of 0 and
'the required buffer size in cbSid.
'In addition, because sDomainName is
'passed as null, cbDomainName returns
'the required buffer size for the lookup
'domain.
success = LookupAccountName(sSystemName, _
sAccountName, _
0&, _
cbSid, _
sDomainName, _
cbDomainName, _
peUse)
'prevent errors
If (success = 0) And (cbSid > 0) Then
'Prepare a buffer into which
'the domain where the account
'name is found will be returned
sDomainName = Space$(cbDomainName)
'create a buffer for the SID and
'call again.
ReDim bSID(0 To cbSid - 1)
'The function attempts to find a SID
'for the specified name by first
'checking a list of well-known SIDs.
'If the name does not correspond to a
'well-known SID, the function checks
'built-in and administratively-defined
'local accounts. Next, the function
'checks the primary domain. If the name
'is not found there, trusted domains
'are checked.
'On Windows 2000/XP, in addition to
'lookup local accounts, local domain
'accounts, and explicitly trusted
'domain accounts, LookupAccountName
'can look up the name for any account
'in any domain in the Windows 2000 forest.
'
'The further 'out' the search has to go,
'the longer it will take to return.
'
'peUse returns a pointer to a SID_NAME_USE
'enumerated type indicating the type of
'the account when the function returns.
'
'A (SID) is a value that uniquely identifies
'a user or group on all Windows NT implementations.
success = LookupAccountName(sSystemName, _
sAccountName, _
bSID(0), _
cbSid, _
sDomainName, _
cbDomainName, _
peUse)
If success > 0 Then
'obtain the domain name
'returned
If cbDomainName > 0 Then
sDomainName = Left$(sDomainName, cbDomainName)
End If
End If
End If
'the call succeeded if success is greater than 0
ValidateUser = success
End Function
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9437124/viewspace-1016752/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 禁用系統帳號(USER_INFO_1008)的例項
- 檢查貨幣是否存在SAP系統中
- 獲取系統帳戶密碼週期的例項密碼
- ajax實現的驗證使用者名稱是否存在程式碼例項
- 微軟登入系統存在漏洞:使用者Office帳號受影響微軟
- 檢查LOGO是否存在Go
- 驗證資料是否存在
- js驗證表單項是否為空例項程式碼JS
- 三分鐘上手openldap帳號系統LDA
- 檢查是否存在truncate或者rebuild的索引Rebuild索引
- 判斷當前使用者是否為系統管理員的例項
- 驗證手機號碼格式的程式碼例項
- js檢測文字框是否為空程式碼例項JS
- Oracle Exp誤匯入系統帳號的補救方法Oracle
- js驗證是否是正整數程式碼例項JS
- 檢視系統中的WWN號
- shell判斷系統路徑中是否存在空格
- 代理檢驗是否可用
- 2 Day DBA-管理Oracle例項-管理使用者帳戶和安全-檢視使用者帳戶Oracle
- Win10系統解封被禁的Xbox One帳號的方法Win10
- 檢測表中行記錄是否已存在
- 檢驗漢字的正規表示式程式碼例項
- windows10系統中如何設定隱藏帳號Windows
- 升級win10系統檢測提示“帳號登陸不符合要求”的解決方法Win10
- 【Insights直播】華為帳號服務,打造全場景安全帳號體系
- javascript如何檢測一個圖片是否存在JavaScript
- python檢測圖片是否存在指令碼Python指令碼
- 檢測checkbox核取方塊是否被選中的例項程式碼
- python怎麼驗證檔案是否存在Python
- 校驗區間是否存在重疊(Python)Python
- 表單驗證手機號碼格式例項程式碼
- win10系統怎麼修改Administrator帳號名Win10
- 檢視linux系統版本號的命令Linux
- Python檢驗一個檔案是否存在,如果不在就自己填寫內容。Python
- linux系統檢視wwn號Linux
- linux 檢視系統版本號Linux
- 在單點登入的實現時,怎樣能把單點登入的帳號和其它應用系統的帳號繫結呢?
- Python3檢查檔案是否存在的常用方法!Python