• 获取所有用户
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用户相关操作的更多相关文章

  1. linux常用命令---用户相关操作

    用户相关操作

  2. Oracle使用——oracle用户相关操作

    前提 以dba角色登录数据库(普通用户没有操作权限):sqlplus / as sysdba 具体操作 创建用户 创建用户 使用默认表空间创建用户 create user xzgxh identifi ...

  3. NO12 useradd-passwd-uname-hostname命令-上传rz下载sz-批量部署- Linux用户相关操作

    24 useradd    #添加用户                        语法:useradd 用户名  例子:ueradd oldboy .25 passwd     #为用户设置或修改 ...

  4. Mysql用户相关操作

    MySQL 默认有个root用户,但是这个用户权限太大,一般只在管理数据库时候才用.如果在项目中要连接 MySQL 数据库,则建议新建一个权限较小的用户来连接. 在 MySQL 命令行模式下输入如下命 ...

  5. windows cmd相关操作

    一:文件夹1. 新建文件夹方式一:md[盘符:\][路径\]新目录例如:md c:\test\newtest 方式二:先使用cmd进入需要新建文件的根目录下,使用md或者mkdir 直接创建文件夹ne ...

  6. Linux之用户相关操作

    1. 创建用户 useradd -m wolf #即创建一个用户并且创建同名的家目录 2. 设置密码 passwd wolf

  7. 第五章 NFS、rsync等统一用户相关操作

    一.统一用户 1.httpd2.NFS挂载目录3.rsync 1.所有服务器统一创建用户 [root@web01 ~]# groupadd www -g 666[root@web01 ~]# user ...

  8. mysql设置指定ip访问,用户权限相关操作

    基础语法GRANT priv_type ON database.table TO user[IDENTIFIED BY [PASSWORD] 'password'] [,user [IDENTIFIE ...

  9. pip的相关操作

    >Python中的pip是什么?能够做些什么? pip是Python中的一个进行包管理的东西,能够下载包.安装包.卸载包......一些列操作 >怎么查看pip的相关信息 在控制台输入: ...

随机推荐

  1. 深入解析QML引擎, 第1部分:QML文件加载

    译者注:这个解析QML引擎的文章共4篇,分析非常透彻,在国内几乎没有找到类似的分析,为了便于国内的QT/QML爱好者和工作者也能更好的学习和理解QML引擎,故将这个系列的4篇文章翻译过来.翻译并不是完 ...

  2. Maven学习(一)-----Maven安装配置总结

    想要安装 Apache Maven 在Windows 系统上, 需要下载 Maven 的 zip 文件,并将其解压到你想安装的目录,并配置 Windows 环境变量. 所需工具 : JDK 1.8 M ...

  3. Eclipse与MySQL数据库连接步骤

    将Eclipse与数据库进行连接的步骤: 1. 下载并配置MySQL 2. 为新建的项目配置mysql的jar包(jdbc和connection的配置) a) 可直接引用外部文件(不建议做,这样项目一 ...

  4. jmeter逻辑控制器

    刚开始学习,只写几种了解的逻辑控制器 1.简单控制器 只用来组合采样器和其他逻辑控制器,不影响jmeter的运行 2.循环控制器 用来循环执行采样器和其他逻辑控制器,例如一个用户发送特定请求多次,即可 ...

  5. Struts2(一.基本介绍,环境搭建及需求分析)

    Struts2框架开发 前言 开发工具:eclipse struts1:老项目使用较多,维护时需要用到 struts2:新项目使用较多 一.特点 1. 无侵入式设计 struts2 与 struts ...

  6. 如何使用phpredis连接Redis的方法

    本文跟大家介绍使用同一VPC内弹性云服务器ECS上的phpredis连接Redis的方法. 更多的客户端的使用方法,请参考https://redis.io/clients 前提条件 已成功申请Redi ...

  7. Golang项目开发管理

    工具 1. task(项目管理,类似于make) go get -u -v github.com/go-task/task/cmd/task 2. gopm(go依赖管理) go get -u git ...

  8. 通过Nrgok映射外网调试微信

    一.注册账号 注册地址:http://www.ngrok.cc/login 登录系统,新增域名 二.下载客户端,修改配置文件 修改ngrok.cfg auth_token值登录平台管理系统可查看 su ...

  9. 1019psp

    1.本周psp: 2.本周进度条: 3.累计进度图(折线图): 4.psp饼状图:

  10. 软件工程-东北师大站-第六次作业PSP

    1.本周PSP 2.本周进度条 3.本周累计进度图 代码累计折线图 博文字数累计折线图 4.本周PSP饼状图