vb.net 当前计算机用户,用VB写的一个组件,实现添加系统用户,并添加到指定组-.NET教程,VB.Net语言...
声明部分
option explicit
const nerr_success = 0
const error_more_data = 234&
const max_preferred_length = -1&
const lg_include_indirect = &h1
const user_priv_user = &h1
const format_message_from_system = &h1000
const nerr_base = 2100
const max_nerr = nerr_base + 899
const load_library_as_datafile = &h2
const format_message_from_hmodule = &h800
type tuser1 ’ level 1
ptrname as long
ptrpassword as long
dwpasswordage as long
dwpriv as long
ptrhomedir as long
ptrcomment as long
dwflags as long
ptrscriptpath as long
end type
type user_info_0
usri0_name as long
end type
type localgroup_info_0
lgrpi0_name as long
end type
type localgroup_user_info_0
lgrui0_name as long
end type
type userinfo_1
username as string
password as string
passwordage as long
privilege as long
homedir as string
comment as long
flags as long
scriptpath as string
end type
type localgroup_members_info_3
lgrmi3_domainandname as long
end type
type user_info_1003
usri1003_password as long
end type
private usr1 as userinfo_1
’用户所在组
declare function netusergetlocalgroups lib “netapi32.dll” (byval servername as string, byval username as string, byval level as long, byval flag as long, bufptr as any, byval prefmaxlen as long, entriesread as long, totalentries as long) as long
’本地组
declare function netlocalgroupenum lib “netapi32.dll” (byval servername as string, byval level as long, bufptr as any, byval prefmaxlen as long, entriesread as long, totalentries as long, resumehandle as long) as long
declare function lstrlen lib “kernel32.dll” alias “lstrlenw” (byval lpszstring as long) as long
declare function lstrcpy lib “kernel32.dll” alias “lstrcpyw” (lpszstring1 as any, lpszstring2 as any) as long
declare function netapibufferfree lib “netapi32.dll” (byval buffer as long) as long
declare sub rtlmovememory lib “kernel32.dll” (destination as any, source as any, byval length as long)
’添加用户
private declare function netuseradd lib “netapi32” (byval servername as string, byval level as long, buffer as any, paramerr as long) as long
’用户列表
declare function netuserenum lib “netapi32.dll” (byval servername as string, byval level as long, byval filter as long, bufptr as any, byval prefmaxlen as long, entriesread as long, totalentries as long, resume_handle as long) as long
’添加到本地组
declare function netlocalgroupaddmembers lib “netapi32.dll” (byval servername as string, byval groupname as string, byval level as long, buf as any, byval totalentries as long) as long
’删除用户
declare function netuserdel lib “netapi32.dll” (servername as byte, username as byte) as long
’从组中删除用户
declare function netgroupdeluser lib “netapi32.dll” (servername as byte, groupname as byte, username as byte) as long
’修改密码
declare function netuserchangepassword lib “netapi32.dll” (byval domainname as string, byval username as string, byval oldpassword as string, byval newpassword as string) as long
private declare function netgetdcname lib “netapi32.dll” (servername as long, domainname as byte, bufptr as long) as long
private declare function loadlibraryex lib “kernel32” alias “loadlibraryexa” (byval lplibfilename as string, byval hfile as long, byval dwflags as long) as long
private declare function netusersetinfo lib “netapi32.dll” (byval servername as string, byval username as string, byval level as long, userinfo as any, parmerror as long) as long
private declare sub lstrcpyw lib “kernel32” (dest as any, byval src as any)
private declare function formatmessage lib “kernel32” alias “formatmessagea” (byval dwflags as long, byval lpsource as long, byval dwmessageid as long, byval dwlanguageid as long, byval lpbuffer as string, byval nsize as long, arguments as any) as long
private declare function freelibrary lib “kernel32” (byval hlibmodule as long) as long
函数部分
修改密码
function changepassword(byval servername as string, byval username as string, byval oldpassword as string, byval newpassword as string)
dim strserver as string, strusername as string
dim strnewpassword as string, stroldpassword as string
dim ui1003 as user_info_1003
dim dwlevel as long
dim lret as string
dim snew as string
’strserver = strconv(servername, vbunicode)
strusername = strconv(username, vbunicode)
’stroldpassword = strconv(oldpassword, vbunicode)
strnewpassword = strconv(newpassword, vbunicode)
if left(servername, 2) = “\\” then
strserver = strconv(servername, vbunicode)
else
’ domain was referenced, get the primary domain controller
strserver = strconv(getprimarydcname(servername), vbunicode)
end if
if oldpassword = “” then
’ administrative over-ride of existing password.
’ does not require old password
dwlevel = 1003
snew = newpassword
ui1003.usri1003_password = strptr(snew)
lret = netusersetinfo(strserver, strusername, dwlevel, ui1003, 0&)
else
’ set the old password and attempt to change the user’s password
stroldpassword = strconv(oldpassword, vbunicode)
lret = netuserchangepassword(strserver, strusername, stroldpassword, strnewpassword)
end if
if lret <> 0 then
displayerror lret
else
msgbox “password change was successful”
end if
end function
添加用户
function useradd(byval servername as string, byval username as string, byval password as string) as string
servername = strconv(servername, vbunicode)
usr1.username = strconv(username, vbunicode)
usr1.password = strconv(password, vbunicode)
usr1.privilege = user_priv_user
usr1.comment = 0
usr1.flags = 0
useradd = netuseradd(servername, 1, usr1, 0)
end function
添加用户到组
function addusertogroup(byval servername as string, byval groupname as string, byval username as string) as long
dim lngwin32apiresultcode as long
dim strservername as string
dim strlocalgroupname as string
dim lngbufptr as long
dim udtlgmeminfo as localgroup_members_info_3
dim strname as string
strservername = strconv(servername, vbunicode)
strlocalgroupname = strconv(groupname, vbunicode)
’strname = strconv(username, vbunicode)
strname = username
udtlgmeminfo.lgrmi3_domainandname = strptr(strname)
lngwin32apiresultcode = netlocalgroupaddmembers(strservername, strlocalgroupname, 3, udtlgmeminfo, 1)
netapibufferfree lngbufptr
end function
列举用户
sub enumusers(cbousers as combobox)
dim lngwin32apiresultcode as long
dim strservername as string
dim lngbufptr as long
dim lngmaxlen as long
dim lngentriesread as long
dim lngtotalentries as long
dim lngresumehandle as long
dim udtuserinfo0 as user_info_0
dim lngentry as long
strservername = strconv(“”, vbunicode)
do
lngwin32apiresultcode = netuserenum(strservername, 0, 0, lngbufptr, lngmaxlen, lngentriesread, lngtotalentries, lngresumehandle)
if (lngwin32apiresultcode = nerr_success) or (lngwin32apiresultcode = error_more_data) then
for lngentry = 0 to lngentriesread – 1
rtlmovememory udtuserinfo0, byval lngbufptr + len(udtuserinfo0) * lngentry, len(udtuserinfo0)
cbousers.additem pointertostring(udtuserinfo0.usri0_name)
next
end if
if lngbufptr <> 0 then
netapibufferfree lngbufptr
end if
loop until lngentriesread = lngtotalentries
end sub
列举本地组
sub enumlocalgroups(lstlocalgroups as listbox) dim lngwin32apiresultcode as long
dim strservername as string
dim lngbufptr as long
dim lngentriesread as long
dim lngtotalentries as long
dim lngresumehandle as long
dim udtlginfo0 as localgroup_info_0
dim lngentry as long
lstlocalgroups.clear
strservername = strconv(“”, vbunicode)
do
lngwin32apiresultcode = netlocalgroupenum(strservername, 0, lngbufptr, max_preferred_length, lngentriesread, lngtotalentries, lngresumehandle)
if (lngwin32apiresultcode = nerr_success) or (lngwin32apiresultcode = error_more_data) then
for lngentry = 0 to lngentriesread – 1
rtlmovememory udtlginfo0, byval lngbufptr + len(udtlginfo0) * lngentry, len(udtlginfo0)
lstlocalgroups.additem pointertostring(udtlginfo0.lgrpi0_name)
next
end if
if lngbufptr <> 0 then
netapibufferfree lngbufptr
end if
loop while lngwin32apiresultcode = error_more_data
end sub
用户所在组
sub enumuserlocalgroups(lstuserlocalgroups as listbox, lstlocalgroups as listbox, cmbuser as combobox)
dim lngwin32apiresultcode as long
dim strservername as string
dim strusername as string
dim lngbufptr as long
dim lngentriesread as long
dim lngtotalentries as long
dim lngresumehandle as long
dim udtlginfo0 as localgroup_user_info_0
dim lngentry as long
dim strlocalgroup as string
dim lnglistcounter as long
lstuserlocalgroups.clear
strservername = strconv(“”, vbunicode)
strusername = strconv(cmbuser.text, vbunicode)
do
lngwin32apiresultcode = netusergetlocalgroups(strservername, strusername, 0, lg_include_indirect, lngbufptr, max_preferred_length, lngentriesread, lngtotalentries)
if (lngwin32apiresultcode = nerr_success) or (lngwin32apiresultcode = error_more_data) then
for lngentry = 0 to lngentriesread – 1
rtlmovememory udtlginfo0, byval lngbufptr + len(udtlginfo0) * lngentry, len(udtlginfo0)
strlocalgroup = pointertostring(udtlginfo0.lgrui0_name)
lstuserlocalgroups.additem strlocalgroup
’with lstlocalgroups
’for lnglistcounter = 0 to .listcount – 1
’if strlocalgroup = .list(lnglistcounter) then
’.removeitem (lnglistcounter)
’end if
’next
’end with
next
end if
if lngbufptr <> 0 then
netapibufferfree lngbufptr
end if
loop until lngentriesread = lngtotalentries
end sub
删除用户
function deluser(byval sname as string, byval uname as string) as long
dim unarray() as byte, snarray() as byte
unarray = uname & vbnullchar
snarray = sname & vbnullchar
deluser = netuserdel(snarray(0), unarray(0))
end function
vb.net 当前计算机用户,用VB写的一个组件,实现添加系统用户,并添加到指定组-.NET教程,VB.Net语言...相关推荐
- python卖水果_小姨开水果店的,所以今天用Python写了一个水果店小系统!
原标题:小姨开水果店的,所以今天用Python写了一个水果店小系统! 前言 今天晚上才刚下班,小姨就提了我最爱吃的榴莲过来,说不吃就坏了. 我一眼就看破了她的用意,哈哈哈 我这个小姨也是一起长大的,她 ...
- ubantu使用vsftp设置ftp上传 java添加系统用户限定ftp登录
ftp业务搭建笔记(安装,启动,配置详解(中文) 1. 使用apt-get 工具安装vsftpd sudo apt-get install vsftpd 如果你是管理员可以使用 apt-get ins ...
- Centos系统添加系统用户操作记录审计
有时候我们需要对线上用户操作记录进行历史记录待出现问题追究责任人,,但Linux系统自带的history命令用户有自行删除权限,那怎么设置可以让用户的操作记录实时记录,并保证普通用户无权删除呢? 1. ...
- Linux添加系统用户
1.添加用户:adduser admin 2.设置密码:passwd admin 3.设置用户组:usermod -g root admin 4.查看是否成功设置root权限:su admin(可以登 ...
- 小姨开水果店的,所以今天用Python写了一个水果店小系统!
前言 今天晚上才刚下班,小姨就提了我最爱吃的榴莲过来,说不吃就坏了. 我一眼就看破了她的用意,哈哈哈 我这个小姨也是一起长大的,她心里的小九九 我在清楚不过了!肯定是有求于我! 然后就直接问他有 ...
- python程序员专用壁纸_043 用python写了一个壁纸切换的系统
程序员换壁纸还是用程序比较好啊,谁让windows切换壁纸的功能那么的垃圾呢 功能如下,这是使用的功能1,初始使用的情况 欢迎使用壁纸切换系统 使用上次的文件夹路径请输入:1 在使用上次的文件夹路径的 ...
- 写的一个简易评委打分系统(内含详细注释)
#include<iostream> using namespace std; #include<vector> #include<deque> #include ...
- 请写出一个智能排班系统的前端页面
下面是一个简单的智能排班系统的前端页面示例: 页面顶部: 标题栏:显示系统名称 "智能排班系统" 导航栏:包括首页.员工管理.排班管理等链接 主要内容: 排班表:以日历形式显示每个 ...
- win7计算机用户文件,win7系统用户文件夹改名的图文教程
win7系统使用久了,好多网友反馈说win7系统用户文件夹改名的问题,非常不方便.有什么办法可以永久解决win7系统用户文件夹改名的问题,面对win7系统用户文件夹改名的图文步骤非常简单,只需要首先, ...
最新文章
- Android各版本新特性
- 【怎样写代码】向现有类型“添加”方法 -- 扩展方法(二):扩展方法的实现与调用
- Python控制流:顺序结构、分支结构、循环结构+for、if ... else、while、if... elif...elif..else、if
- 在Java中实现单例模式的有效方法是什么? [关闭]
- Ubuntu14搭建配置青岛大学OJ系统
- linux cer证书转为jks,常见SSL证书格式介绍以及SSL证书格式转化方法
- 对CloseHandle用法的理解
- 雷凌linux车机升级_绿老师学堂:15万合资车谁更“聪明”?体验思域/福克斯/雷凌车机...
- 牛人开发软件-网站收集
- 用好IE9浏览器必须要知道的九件事
- BAT-局域网内在线电脑IP
- forms Build中的触发器
- 汇编语言程序设计--基于ARM
- 关于jQuery通知插件toastr的使用
- java中分解json数据,java解析JSON数据详解
- app逆向案例分析-极速抖音
- JS基础(乾坤未定,你我皆是黑马4-2)
- 解决USB无法识别问题
- 【Python】PEP8规范
- JSP教师辅助办公软件教学进程管理系统yeclipse开发mysql数据库bs框架java编程jdbc详细设计