禁用系統帳號(USER_INFO_1008)的例項
[@more@]
Option Explicit
Private Const ERROR_SUCCESS As Long = 0
Private Const UF_SCRIPT As Long = &H1
Private Const UF_ACCOUNTDISABLE As Long = &H2
Private Type USER_INFO_1008
usri1008_flags As Long
End Type
Private Declare Function NetUserSetInfo Lib "Netapi32" _
(servername As Byte, _
username As Byte, _
ByVal level As Long, _
bufptr As Long, _
parm_err As Long) As Long
Private Declare Function NetApiBufferFree Lib "Netapi32" _
(ByVal Buffer As Long) As Long
Private Sub Form_Load()
With Label1
.Caption = "Account:"
.AutoSize = True
.Move 200, 400
End With
With Text1
.Text = "(enter a user name)"
.Move 1000, 360, 1600, 285
End With
With Label2
.Caption = "(result)"
.AutoSize = True
.WordWrap = True
.Move 2800, 400, 2200
End With
With Check1
.Caption = "Check to confirm disable of this account"
.Move 1000, 800, 3400, 345
End With
With Command1
.Caption = "Disable Account"
.Move 1000, 1200, 1600, 345
End With
End Sub
Private Sub Command1_Click()
Dim bLockout As Boolean
Dim sUser As String
Dim success As Boolean
'set up
bLockout = Check1.Value = vbChecked
sUser = Text1.Text
Label2.Caption = "working..."
Label2.Refresh
'call
success = DisableAccount(bLockout, sUser, "")
'result
Select Case success
Case True
Label2.Caption = "NetUserSetInfo successful: account disabled"
Case Else
Label2.Caption = "Unknown error"
End Select
End Sub
Private Function DisableAccount(bDisableAccount As Boolean, _
sUsername As String, _
Optional sServer As String = vbNullString) As Long
Dim bServer() As Byte
Dim bUser() As Byte
Dim parm_err As Long
Dim ui1008 As USER_INFO_1008
'safety check
If bDisableAccount = True Then
bUser = sUsername & vbNullChar
bServer = QualifyServer(sServer) & vbNullChar
'Set the flags. UF_SCRIPT is required
'for LAN Manager 2.0 and Windows NT and later
ui1008.usri1008_flags = UF_SCRIPT Or UF_ACCOUNTDISABLE
'Because the UDT contains only
'one member defined As Long, pass
'the value directly in NetUserSetInfo.
'Otherwise we need to use CopyMemory.
DisableAccount = NetUserSetInfo(bServer(0), _
bUser(0), _
1008, _
ui1008.usri1008_flags, _
parm_err) = ERROR_SUCCESS
NetApiBufferFree ui1008.usri1008_flags
End If 'bDisableAccount
End Function
Private Function QualifyServer(ByVal sServer As String) As String
'if nullstring was passed, the
'API does not expect slashes in
'the server name
If Len(sServer) > 0 Then
'are already two slashes
'preceding the server name?
If Left$(sServer, 2) = "" Then
'there are, so the server is already
'qualified; return the passed string
QualifyServer = sServer
Else
'there aren't two, but is there one?
If Left$(sServer, 1) = "" Then
'yes, so add one more
QualifyServer = "" & sServer
Else
'the string needs both
QualifyServer = "" & sServer
End If 'Left$(sServer, 1) <> ""
End If 'Left$(sServer, 2) = ""
Else
'empty string passed, so return it
QualifyServer = sServer
End If 'Len(sServer)
End Function
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9437124/viewspace-1016754/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 檢驗系統帳號是否存在的例項
- 獲取系統帳戶密碼週期的例項密碼
- 三分鐘上手openldap帳號系統LDA
- Oracle Exp誤匯入系統帳號的補救方法Oracle
- Windows Vista 內建管理員帳號被禁用(轉)Windows
- Win10系統下如何禁用關閉Administraotr帳戶Win10
- 關於SQL Serve資料庫r帳號被禁用的處理方法SQL資料庫
- Win10系統解封被禁的Xbox One帳號的方法Win10
- 禁用滑鼠右鍵例項程式碼
- JavaScript禁用tab鍵程式碼例項JavaScript
- Win10系統禁用管理員帳戶後無法進入系統怎麼解決Win10
- win10自定義禁用系統啟動項的方法Win10
- windows10系統中如何設定隱藏帳號Windows
- jQuery禁用滑鼠右鍵程式碼例項jQuery
- js如何禁用tab鍵例項程式碼JS
- 【Insights直播】華為帳號服務,打造全場景安全帳號體系
- win10系統怎麼修改Administrator帳號名Win10
- 在 Linux 系統中禁用與解禁使用者的賬號Linux
- 在單點登入的實現時,怎樣能把單點登入的帳號和其它應用系統的帳號繫結呢?
- 網頁禁用滑鼠右鍵程式碼例項網頁
- HP UNIX系統優化例項優化
- Oracle使用系統級觸發器審計重要帳號的DDL語句Oracle觸發器
- Insights直播回顧| 華為帳號服務,打造全場景安全帳號體系
- jQuery實現的禁用右鍵選單程式碼例項jQuery
- Linux系統中的basename命令使用例項Linux
- 模板與例項在系統中的應用
- RAC資料庫啟用、禁用一個例項資料庫
- 公用查詢帳號的管理
- 系統配置的最佳化:例項的初始配置
- 微軟登入系統存在漏洞:使用者Office帳號受影響微軟
- OpenGL Shader例項,OpenGL 粒子系統
- 系統最佳化例項一則
- Bash 例項:探討 ebuild 系統(轉)UI
- 營帳系統之二:賬務系統概念
- Unity 熱更新例項一、C#Light 和UI系統使用例項UnityC#UI
- 禁用文字選擇、右鍵選單例項程式碼單例
- 2 Day DBA-管理Oracle例項-關於管理帳戶和許可權-SYSDBA和SYSOPER系統許可權Oracle
- asp.net系統的使用者將自己的帳號繫結到特定的ip上面ASP.NET