using System;
using SystemCollectionsGeneric;
using SystemText;
using SystemRuntimeInteropServices;
using SystemTextRegularExpressions;
using DevSDKWinNT;
using DevSDK;
namespace DevSDKWinNT
{
public class NetUser:Common
{
//创建用户
[DllImport("Netapi32dll")]
extern static int NetUserAdd([MarshalAs(UnmanagedTypeLPWStr)] string sName, int Level, ref USER_INFO_1 buf, int parm_err);
//修改用户密码
[DllImport("Netapi32dll")]
extern static int NetUserChangePassword([MarshalAs(UnmanagedTypeLPWStr)] string sName,[MarshalAs(UnmanagedTypeLPWStr)] string UserName,[MarshalAs(UnmanagedTypeLPWStr)] string OldPassword,[MarshalAs(UnmanagedTypeLPWStr)] string NewPassword);
//删除用户
[DllImport("Netapi32dll")]
extern static int NetUserDel([MarshalAs(UnmanagedTypeLPWStr)] string sName,[MarshalAs(UnmanagedTypeLPWStr)] string UserName);
//枚举全部用户
[DllImport("Netapi32dll")]
extern static int NetUserEnum([MarshalAs(UnmanagedTypeLPWStr)] string sName,int Level,int filter,out IntPtr bufPtr,int Prefmaxlen,out int Entriesread,out int Totalentries,out int Resume_Handle);
//获取用户信息
[DllImport("Netapi32dll")]
extern static int NetUserGetInfo([MarshalAs(UnmanagedTypeLPWStr)] string sName,[MarshalAs(UnmanagedTypeLPWStr)] string UserName,int Level,out IntPtr intptr);
//获取用户所在本地组
[DllImport("Netapi32dll")]
extern static int NetUserGetLocalGroups([MarshalAs(UnmanagedTypeLPWStr)] string sName,[MarshalAs(UnmanagedTypeLPWStr)] string UserName,int Level,int Flags,out IntPtr intptr,int Prefmaxlen,out int Entriesread,out int Totalentries);
//修改用户信息
[DllImport("Netapi32dll")]
extern static int NetUserSetInfo([MarshalAs(UnmanagedTypeLPWStr)] string sName, [MarshalAs(UnmanagedTypeLPWStr)] string UserName, int Level, ref USER_INFO_1 bufptr, int parm_err);
//释放API
[DllImport("Netapi32dll")]
extern static int NetApiBufferFree(IntPtr Buffer);
[StructLayout(LayoutKindSequential, CharSet = CharSetUnicode)]
public struct LOCALGROUP_USERS_INFO_0
{
public string GroupName;
}
[StructLayout(LayoutKindSequential, CharSet = CharSetUnicode)]
public struct USER_INFO_1
{
public string sName; //用户名
public string sPass; //用户密码
public int PasswordAge; //密码级别
public int sPriv; //帐户类型 1
public string sHomeDir; //用户主目录 null
public string sComment; //用户描述
public int sFlags; //用户权限
public string sScriptPath; //登陆脚本路径 null
}
//枚举全部用户
public string UserEnum()
{
string tempStr = "<xml version=\"10\" encoding=\"gb2312\" >\r\n";
tempStr += "<INFO>\r\n";
int Entriesread;
int TotalEntries;
int Resume_Handle;
IntPtr bufPtr;
if (NetUserEnum(null, 1, 0, out bufPtr, -1, out Entriesread, out TotalEntries, out Resume_Handle) != 0)
{
throw (new Exception("枚举全部用户失败"));
}
if (Entriesread > 0)
{
USER_INFO_1[] UserInfo = new USER_INFO_1[Entriesread];
IntPtr iter = bufPtr;
for (int i = 0; i < Entriesread; i++)
{
UserInfo[i] = (USER_INFO_1)MarshalPtrToStructure(iter, typeof(USER_INFO_1));
iter = (IntPtr)((int)iter + MarshalSizeOf(typeof(USER_INFO_1)));
tempStr += "<ITEM value=\"" + UserInfo[i]sComment + "\">" + UserInfo[i]sName + "</ITEM>\r\n";
}
tempStr += "</INFO>";
}
NetApiBufferFree(bufPtr);
return tempStr;
}
//读取用户信息
public string UserGetInfo(string UserName)
{
string tmpStr = "<xml version=\"10\" encoding=\"gb2312\" >\r\n";
tmpStr += "<INFO>\r\n";
IntPtr bufPtr;
USER_INFO_1 UserInfo = new USER_INFO_1();
if (NetUserGetInfo(null, UserNameToString(), 1, out bufPtr) != 0)
{
throw (new Exception("读取用户信息失败"));
}
else
{
UserInfo = (USER_INFO_1)MarshalPtrToStructure(bufPtr, typeof(USER_INFO_1));
tmpStr += "<NAME>" + UserInfosName + "</NAME>\r\n";
tmpStr += "<PASS>" + UserInfosPass + "</PASS>\r\n";
tmpStr += "<DESC>" + UserInfosComment + "</DESC>\r\n";
tmpStr += "</INFO>";
NetApiBufferFree(bufPtr);
return tmpStr;
}
}
//删除用户
public bool UserDelete(string UserName)
{
if (NetUserDel(null, UserNameToString()) != 0)
{
throw (new Exception("删除用户失败"));
}
else
{
return true;
}
}
//修改用户信息
public bool UserSetInfo(string UserName,string NewUserName, string UserPass, string sDescription)
{
USER_INFO_1 UserInfo = new USER_INFO_1();
UserInfosName = NewUserNameToString();
UserInfosPass = UserPassToString();
UserInfoPasswordAge = 0;
UserInfosPriv = 1;
UserInfosHomeDir = null;
UserInfosComment = sDescriptionToString();
UserInfosFlags = 0x10040;
UserInfosScriptPath = null;
if (NetUserSetInfo(null, UserNameToString(), 1, ref UserInfo, 0) != 0)
{
throw (new Exception("用户信息修改失败"));
}
else
{
return true;
}
}
//创建系统用户
public bool UserAdd(string UserName, string UserPass,string sDescription)
{
USER_INFO_1 UserInfo = new USER_INFO_1();
UserInfosName = UserNameToString();
UserInfosPass = UserPassToString();
UserInfoPasswordAge = 0;
UserInfosPriv = 1;
UserInfosHomeDir = null;
UserInfosComment = sDescriptionToString();
//UserInfosFlags = 0x0040;
UserInfosFlags = 0x10040;
UserInfosScriptPath = null;
if (NetUserAdd(null, 1, ref UserInfo, 0) != 0)
{
throw (new Exception("创建系统用户失败"));
}
else
{
return true;
}
}
//修改用户密码
public bool UserChangePassword(string UserName, string OldPassword, string NewPassword)
{
if (NetUserChangePassword(null, UserNameToString(), OldPasswordToString(), NewPasswordToString()) != 0)
{
throw (new Exception("修改系统用户密码失败"));
}
else
{
return true;
}
}
//获取用户全部所在本地组
public string UserGetLocalGroups(string UserName)
{
int EntriesRead;
int TotalEntries;
IntPtr bufPtr;
string tempStr = "<xml version=\"10\" encoding=\"gb2312\" >\r\n";
tempStr += "<INFO>\r\n";
if (NetUserGetLocalGroups(null, UserNameToString(), 0, 0, out bufPtr, 1024, out EntriesRead, out TotalEntries) != 0)
{
throw (new Exception("读取用户所在本地组失败"));
}
if (EntriesRead > 0)
{
LOCALGROUP_USERS_INFO_0[] GroupInfo = new LOCALGROUP_USERS_INFO_0[EntriesRead];
IntPtr iter = bufPtr;
for (int i = 0; i < EntriesRead; i++)
{
GroupInfo[i] = (LOCALGROUP_USERS_INFO_0)MarshalPtrToStructure(iter, typeof(LOCALGROUP_USERS_INFO_0));
iter = (IntPtr)((int)iter + MarshalSizeOf(typeof(LOCALGROUP_USERS_INFO_0)));
tempStr += "<GROUP>" + GroupInfo[i]GroupName + "</GROUP>\r\n";
}
tempStr += "</INFO>";
NetApiBufferFree(bufPtr);
}
return tempStr;
}
}
}
您好!感谢您对火狐产品的支持!
所谓的凭据管理器,并不是用于管理登录任何Internet上的网站和网络,而是用于保存和管理与本机建立了某种特殊关系的登录凭据,比如本地计算机局域网中建立的交互式家庭组、远程桌面登录、以及安装了远程的Windows Live ID链接程序等。简单的说就是,使用凭据管理器简化登录步骤是必须在远端和本地都建立有某种联系的程序才行,所以通过简单的将URL、用户名及密码添加到凭据管理器的普通凭据中是无法简化网站登录的。
火狐浏览器使用的是Gecko内核,是一款开源、安全的浏览器,拥有非常强大的扩展功能,可以根据自己的需求定制浏览体验。您可以在火狐社区了解更多内容。
希望我的回答对您有所帮助,如有疑问,欢迎继续在本平台咨询。
windows10凭据管理器有什么用
点开始,然后在所有应用下面那个空白的搜索栏里键入 “凭据管理器” 会有一条出来,点击即可打开
如果从控制面板打开,是在用户账户里,有个凭据管理器
1、首先在Win7系统的开始按钮中选择控制面板选项;
2、接着在d出来的控制面板中,点击“用户账户和家庭安全”项;
3、接着在d出来的界面中点击“凭据管理器”;
4、最后点击“添加Windows凭据”这里就可以创建你的凭证了。
以上就是关于C#代码实现对Windows凭据的管理全部的内容,包括:C#代码实现对Windows凭据的管理、请问火狐浏览器如何调用windows凭据管理器中的凭据、什么是Windows 10中的凭据すδ等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)