Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Trying my first steps in c# : create local user account, check if os is english, german or something other, choose groupname and move into it [closed]
- using System;
- using System.DirectoryServices;
- using System.Globalization;
- using System.Security.Permissions;
- using System.Threading;
- [assembly:SecurityPermission( SecurityAction.RequestMinimum, ControlThread = true )]
- class CreateUser
- {
- static void Main(string[] args)
- {
- try
- {
- // Parameter for the account
- string s_Username = "EmpService";
- string s_Password = "password";
- string s_Description = "Empirum Service User for Management";
- // string s_Group1 = "Administrators";
- // string s_Group2 = "Administratoren";
- // Check if Useraccount allready exists
- private bool Check(string s_username)
- {
- DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
- foreach (DirectoryEntry child in entry.Children)
- {
- if (child.SchemaClassName == "User")
- {
- if (child.Name == s_username)
- {
- return true;
- Console.WriteLine("User Account allready exists.");
- {
- }
- }
- return false;
- public static CultureInfo CurrentCulture { get; };
- if (CultureInfo.CurrentCulture.Name.StartsWith("de-"))
- {
- string s_group= "Administratoren";
- Console.WriteLine (" OS Language is GERMAN.");
- }
- else
- {
- string s_group = "Administrators";
- Console.WriteLine("OS Language is NOT German.");
- }
- // Create User Account
- DirectoryEntry NewUser = AD.Children.Add(s_Username, "user");
- // Useraccount-Settings
- NewUser.Invoke("SetPassword", new object[] { s_Password });
- NewUser.Invoke("Put", new object[] { "Description", s_Description });
- // Add User to a Group, for example
- // Check if OS is German or English
- // if OS is english, use "Administrators" as group
- // if OS is german, use "Administratoren" as group
- // grp = AD.Children.Find("Guests", "group");
- // if (grp != null) { grp.Invoke("Add", new object[] { NewUser.Path.ToString() }); }
- // needs to be completed
- // SuccessMessage
- NewUser.CommitChanges();
- Console.WriteLine("EmpServiceBenutzer erfolgreich angelegt.");
- }
- catch (Exception err)
- {
- // ErrorMessage
- Console.WriteLine(err.Message);
- }}
- ;
- }
Add Comment
Please, Sign In to add comment