2020-07-03 | C# | UNLOCK

C#实现的Netapi32添加用户

没办法绕过360就没往下弄加组的了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Runtime.InteropServices;

class netuser{
[DllImport("Netapi32.dll",CharSet = CharSet.Unicode)]
extern static int NetUserAdd([MarshalAs(UnmanagedType.LPWStr)] string sName, int Level, ref USER_INFO_1 buf, int parm_err);

public static void Main(String[] args){
UserAdd("test","testmyC#API","testmyC#netapi32NetUserAdd");
}
public static bool UserAdd(string UserName, string UserPass,string sDescription)
{
USER_INFO_1 UserInfo = new USER_INFO_1();
UserInfo.sName = UserName.ToString();
UserInfo.sPass = UserPass.ToString();
UserInfo.PasswordAge = 0;
UserInfo.sPriv = 1;
UserInfo.sHomeDir = null;
UserInfo.sComment = sDescription.ToString();
//UserInfo.sFlags = 0x0040;
UserInfo.sFlags = 0x10040;
UserInfo.sScriptPath = null;
if (NetUserAdd(null, 1, ref UserInfo, 0) != 0)
{
throw (new Exception("创建系统用户失败"));
}
else
{
return true;
}
}
[StructLayout( LayoutKind.Sequential, CharSet = CharSet.Unicode )]
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
}
}
C#

评论加载中