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的相关信息 在控制台输入: ...
随机推荐
- Awesome TensorFlow
Awesome TensorFlow A curated list of awesome TensorFlow experiments, libraries, and projects. Inspi ...
- 【UGUI】 (二)--------- 小地图
在绝大多数游戏中,小地图都是极为常见的一个模块而且十分重要.在Unity里面如何制作一个地图其实也是比较简单的 一. 创建玩家与敌人 创建一个Capsule,命名为Player,代表我们的游戏玩家,创 ...
- 【洛谷】题解 P1056 【排座椅】
题目链接 因为题目说输入保证会交头接耳的同学前后相邻或者左右相邻,所以一对同学要分开有且只有一条唯一的通道才能把他们分开. 于是可以吧这条通道累加到一个数组里面.应为题目要求纵列的通道和横列的通道条数 ...
- android 签名相关
查看keystorekeytool -list -v -keystore debug.keystoreapk签名不带别名 apksigner sign --ks debug.keystore test ...
- Python 日志记录与程序流追踪(基础篇)
日志记录(Logging) More than print: 每次用 terminal debug 时都要手动在各种可能出现 bug 的地方 print 相关信息来确认 bug 的位置: 每次完成 d ...
- linux-ubuntu配置通过22端口远程连接
当安装好ubuntu后获取到对应主机的ip地址,要想通过类似xshell这样的远程连接工具连接到ubuntu主机,需要在你刚刚安装好的ubuntu主机上安装openssh这个软件,才能通过远程来连接u ...
- mysql 性能优化 20 条建议
MySQL性能优化的最佳20+条经验 2009年11月27日陈皓发表评论阅读评论100,946 人阅读 今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性 ...
- USACO 1.3.2 Barn Repair 修理牛棚(贪心)
Description 在一个夜黑风高,下着暴风雨的夜晚,农民约翰的牛棚的屋顶.门被吹飞了. 好在许多牛正在度假,所以牛棚没有住满. 剩下的牛一个紧挨着另一个被排成一行来过夜. 有些牛棚里有牛,有些没 ...
- 福大软工1816 ·软工之404NoteFound团队选题报告
目录 NABCD分析引用 N(Need,需求): A(Approach,做法): B(Benefit,好处): C(Competitors,竞争): D(Delivery,交付): 初期 中期 个人贡 ...
- 【IdentityServer4文档】- 使用密码保护 API
使用密码保护 API OAuth 2.0 协议允许资源拥有者给客户端密码授权:客户端向令牌服务发送用户密码,以获取代表该用户的访问令牌. 该规范建议仅将“资源所有者密码授予”用于“可信”(或旧版)应用 ...