Windows用户相关操作
- 获取所有用户
NET_API_STATUS NetUserEnum(
LPCWSTR servername,
DWORD level,
DWORD filter,
LPBYTE* bufptr,
DWORD prefmaxlen,
LPDWORD entriesread,
LPDWORD totalentries,
LPDWORD resume_handle
);
#ifndef UNICODE
#define UNICODE
#endif #include <stdio.h>
#include <assert.h>
#include <windows.h>
#include <lm.h> int wmain(int argc, wchar_t *argv[])
{
LPUSER_INFO_0 pBuf = NULL;
LPUSER_INFO_0 pTmpBuf;
DWORD dwLevel = ;
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
DWORD dwEntriesRead = ;
DWORD dwTotalEntries = ;
DWORD dwResumeHandle = ;
DWORD i;
DWORD dwTotalCount = ;
NET_API_STATUS nStatus;
LPTSTR pszServerName = NULL; if (argc > )
{
fwprintf(stderr, L"Usage: %s [\\\\ServerName]\n", argv[]);
exit();
}
// The server is not the default local computer.
//
if (argc == )
pszServerName = argv[];
wprintf(L"\nUser account on %s: \n", pszServerName);
//
// Call the NetUserEnum function, specifying level 0;
// enumerate global user account types only.
//
do // begin do
{
nStatus = NetUserEnum(pszServerName,
dwLevel,
FILTER_NORMAL_ACCOUNT, // global users
(LPBYTE*)&pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
&dwResumeHandle);
//
// If the call succeeds,
//
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
//
// Loop through the entries.
//
for (i = ; (i < dwEntriesRead); i++)
{
assert(pTmpBuf != NULL); if (pTmpBuf == NULL)
{
fprintf(stderr, "An access violation has occurred\n");
break;
}
//
// Print the name of the user account.
//
wprintf(L"\t-- %s\n", pTmpBuf->usri0_name); pTmpBuf++;
dwTotalCount++;
}
}
}
//
// Otherwise, print the system error.
//
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated buffer.
//
if (pBuf != NULL)
{
NetApiBufferFree(pBuf);
pBuf = NULL;
}
}
// Continue to call NetUserEnum while
// there are more entries.
//
while (nStatus == ERROR_MORE_DATA); // end do
//
// Check again for allocated memory.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
//
// Print the final count of users enumerated.
//
fprintf(stderr, "\nTotal of %d entries enumerated\n", dwTotalCount); return ;
}
- 获取用户信息
NET_API_STATUS NetUserGetInfo(
LPCWSTR servername,
LPCWSTR username,
DWORD level,
LPBYTE* bufptr
);
#ifndef UNICODE
#define UNICODE
#endif #include <stdio.h>
#include <windows.h>
#include <lm.h> int wmain(int argc, wchar_t *argv[])
{
DWORD dwLevel = ;
LPUSER_INFO_10 pBuf = NULL;
NET_API_STATUS nStatus; if (argc != )
{
fwprintf(stderr, L"Usage: %s \\\\ServerName UserName\n", argv[]);
exit();
}
//
// Call the NetUserGetInfo function; specify level 10.
//
nStatus = NetUserGetInfo(argv[],
argv[],
dwLevel,
(LPBYTE *)&pBuf);
//
// If the call succeeds, print the user information.
//
if (nStatus == NERR_Success)
{
if (pBuf != NULL)
{
wprintf(L"\n\tAccount: %s\n", pBuf->usri10_name);
wprintf(L"\tComment: %s\n", pBuf->usri10_comment);
wprintf(L"\tUser comment: %s\n", pBuf->usri10_usr_comment);
wprintf(L"\tFull name: %s\n", pBuf->usri10_full_name);
}
}
// Otherwise, print the system error.
//
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf); return ;
}
- 修改用户信息
NET_API_STATUS NetUserSetInfo(
LPCWSTR servername,
LPCWSTR username,
DWORD level,
LPBYTE buf,
LPDWORD parm_err
);
#ifndef UNICODE
#define UNICODE
#endif #include <stdio.h>
#include <windows.h>
#include <lm.h> int wmain(int argc, wchar_t *argv[])
{
DWORD dwLevel = ;
USER_INFO_1008 ui;
NET_API_STATUS nStatus; if (argc != )
{
fwprintf(stderr, L"Usage: %s \\\\ServerName UserName\n", argv[]);
exit();
}
// Fill in the USER_INFO_1008 structure member.
// UF_SCRIPT: required for LAN Manager 2.0 and
// Windows NT and later.
//
ui.usri1008_flags = UF_SCRIPT | UF_ACCOUNTDISABLE;
//
// Call the NetUserSetInfo function
// to disable the account, specifying level 1008.
//
nStatus = NetUserSetInfo(argv[],
argv[],
dwLevel,
(LPBYTE)&ui,
NULL);
//
// Display the result of the call.
//
if (nStatus == NERR_Success)
fwprintf(stderr, L"User account %s has been disabled\n", argv[]);
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus); return ;
}
- 增加用户
NET_API_STATUS NetUserAdd(
LMSTR servername,
DWORD level,
LPBYTE buf,
LPDWORD parm_err
);
#ifndef UNICODE
#define UNICODE
#endif #include <stdio.h>
#include <windows.h>
#include <lm.h> int wmain(int argc, wchar_t *argv[])
{
USER_INFO_1 ui;
DWORD dwLevel = ;
DWORD dwError = ;
NET_API_STATUS nStatus; if (argc != )
{
fwprintf(stderr, L"Usage: %s \\\\ServerName UserName\n", argv[]);
exit();
}
//
// Set up the USER_INFO_1 structure.
// USER_PRIV_USER: name identifies a user,
// rather than an administrator or a guest.
// UF_SCRIPT: required for LAN Manager 2.0 and
// Windows NT and later.
//
ui.usri1_name = argv[];
ui.usri1_password = argv[];
ui.usri1_priv = USER_PRIV_USER;
ui.usri1_home_dir = NULL;
ui.usri1_comment = NULL;
ui.usri1_flags = UF_SCRIPT;
ui.usri1_script_path = NULL;
//
// Call the NetUserAdd function, specifying level 1.
//
nStatus = NetUserAdd(argv[],
dwLevel,
(LPBYTE)&ui,
&dwError);
//
// If the call succeeds, inform the user.
//
if (nStatus == NERR_Success)
fwprintf(stderr, L"User %s has been successfully added on %s\n",
argv[], argv[]);
//
// Otherwise, print the system error.
//
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus); return ;
}
- 用户删除
NET_API_STATUS NetUserDel(
LPCWSTR servername,
LPCWSTR username
);
#ifndef UNICODE
#define UNICODE
#endif #include <stdio.h>
#include <windows.h>
#include <lm.h> int wmain(int argc, wchar_t *argv[])
{
DWORD dwError = ;
NET_API_STATUS nStatus;
//
// All parameters are required.
//
if (argc != )
{
fwprintf(stderr, L"Usage: %s \\\\ServerName UserName\n", argv[]);
exit();
}
//
// Call the NetUserDel function to delete the share.
//
nStatus = NetUserDel(argv[], argv[]);
//
// Display the result of the call.
//
if (nStatus == NERR_Success)
fwprintf(stderr, L"User %s has been successfully deleted on %s\n",
argv[], argv[]);
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus); return ;
}
Windows用户相关操作的更多相关文章
- linux常用命令---用户相关操作
用户相关操作
- Oracle使用——oracle用户相关操作
前提 以dba角色登录数据库(普通用户没有操作权限):sqlplus / as sysdba 具体操作 创建用户 创建用户 使用默认表空间创建用户 create user xzgxh identifi ...
- NO12 useradd-passwd-uname-hostname命令-上传rz下载sz-批量部署- Linux用户相关操作
24 useradd #添加用户 语法:useradd 用户名 例子:ueradd oldboy .25 passwd #为用户设置或修改 ...
- Mysql用户相关操作
MySQL 默认有个root用户,但是这个用户权限太大,一般只在管理数据库时候才用.如果在项目中要连接 MySQL 数据库,则建议新建一个权限较小的用户来连接. 在 MySQL 命令行模式下输入如下命 ...
- windows cmd相关操作
一:文件夹1. 新建文件夹方式一:md[盘符:\][路径\]新目录例如:md c:\test\newtest 方式二:先使用cmd进入需要新建文件的根目录下,使用md或者mkdir 直接创建文件夹ne ...
- Linux之用户相关操作
1. 创建用户 useradd -m wolf #即创建一个用户并且创建同名的家目录 2. 设置密码 passwd wolf
- 第五章 NFS、rsync等统一用户相关操作
一.统一用户 1.httpd2.NFS挂载目录3.rsync 1.所有服务器统一创建用户 [root@web01 ~]# groupadd www -g 666[root@web01 ~]# user ...
- mysql设置指定ip访问,用户权限相关操作
基础语法GRANT priv_type ON database.table TO user[IDENTIFIED BY [PASSWORD] 'password'] [,user [IDENTIFIE ...
- pip的相关操作
>Python中的pip是什么?能够做些什么? pip是Python中的一个进行包管理的东西,能够下载包.安装包.卸载包......一些列操作 >怎么查看pip的相关信息 在控制台输入: ...
随机推荐
- Mongodb大数据语法大全
JSON和MONGODBJSON不止是一种交换数据的方式,也是一种存储数据的良好方式,实际上MONGODB并未使用JSON存储数据,而是使用由MONGODB团队开发的一种称为BSON的开放数据格式. ...
- selenium 各种很奇葩的异常
问题1:使用selenium3+java的脚本模拟登陆时,总是提示用户名,密码错误 解决方法:1 在执行输入用户名和密码的代码之前,加上driver.navigate().refresh(); QQ群 ...
- python序列和其它类型的比较
序列对象可以与相同类型的其他对象比较.它们使用 字典顺序 进行比较:首先比较两个python序列的第一个元素,如果不同,那么这就决定了比较操作的结果.如果它们相同,就再比较每个序列的第二个元素,以此类 ...
- rz和sz上传下载文件
安装软件包 yum install lrzsz 上传文件,输入rz选择文件上传(可以按住shift键多选) # rz sz 下载文件到本地,选择保存文件夹 # sz dd xshell设 ...
- python sys模块使用详情
python常用模块目录 sys模块提供了一系列有关Python运行环境的变量和函数.1.sys.argv可以用sys.argv获取当前正在执行的命令行参数的参数列表(list).变量解释sys.ar ...
- Is It A Tree?(并查集)
Description A tree is a well-known data structure that is either empty (null, void, nothing) or is a ...
- 作业 20181016-1 Alpha阶段贡献分配规则
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2244 条件:八位同学,总共80分贡献分(贡献分总数以实际为准),投票方式 ...
- 四则运算(Android)版
实验题目: 将小学四则运算整合成网页版或者是Android版.实现有无余数,减法有无负数.... 设计思路: 由于学到的基础知识不足,只能设计简单的加减乘除,界面设计简单,代码量少,只是达到了入门级的 ...
- HDU 5672 String
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5672 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- ubuntu16.04卸载火狐,Amazon
一.卸载火狐: . dpkg --get-selections |grep firefox .sudo apt-get purge firefox unity-scope-firefoxbookmar ...