Issue of user account

Peter_1985 2,736 Reputation points
2022-11-14T09:47:15.917+00:00

Hi,
On C# project, I used Powershell command to create new user and furthermore, I can make use of such user account to send out message with a success. But I cannot out show out such user account within Computer management. How to list out such user account and even to remove it?

Developer technologies | C#
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sreeju Nair 12,666 Reputation points
    2022-11-14T14:00:29.643+00:00

    I believe you might require to provide some more information. Anyhow, are you creating a user in your database? I mean the Identity user, then that user will not come under the account under computer management as they are just made inside the database.

    If you made the local user account using PowerShell, it must appear in the Computer management. Refer the following link to understand how can you create a local user account using PowerShell.

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/new-localuser?view=powershell-5.1

    Hope this helps


  2. Jack J Jun 25,296 Reputation points
    2022-11-29T02:28:38.747+00:00

    @ackson1990-7147, Welcome to Microsoft Q&A,

    I could use the WMI to list all the user accounts that appears in the Computer management , please refer to the following code.

    ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_UserAccount");  
      
                foreach (ManagementObject queryObj in searcher.Get())  
                    Console.WriteLine("Name: {0}", queryObj["Name"]);  
    

    Tested result and Compter management:

    265032-image.png

    Updated for creating user in c#:

     DirectoryEntry AD = new DirectoryEntry("WinNT://" +  
      Environment.MachineName + ",computer");  
      DirectoryEntry NewUser = AD.Children.Add("TestUser1", "user");  
      NewUser.Invoke("SetPassword", new object[] { "#12345Abc" });  
      NewUser.Invoke("Put", new object[] { "Description", "Test User from .NET" });  
       NewUser.CommitChanges();  
    

    266787-2.png

    Best Regards,
    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.