none
Failing to get the UserName and Domain Name From ManagementObjectCollection RRS feed

  • Question

  • I am failing to get the Domain name and user name in wrong format using System.Management.ManagementObjectCollection , From the Management object collection when am retrieving the "Username" as it is coming in the below format.

    <SystemName>//<DomainName>//<UserName>

    <SystemName> is concatenating with Domain name and user name . 

    After Changing the PC  name and restarting ,The Domain name and Username getting correct from the ManagementObjectCollection in the correct format<DomainName>//<UserName>

    I followed the steps :

    1) Hosted the win8.1 PC with Microsoft Credentials

    Please help anyone ..!


    Monday, January 21, 2019 3:31 PM

All replies

  • I'm confused about your problem. You're saying that you're getting one format if the user account comes from a machine that differs from the current machine but a different format if they are the same? That is the expected behavior.  If you rename a machine then the user accounts are using the old name until you reboot. As far as the system is concerned they are coming from a different machine. I see nothing wrong with this.

    To handle this scenario modify your parsing logic to handle multiple slashes. If you get 2 values then you have domain/user. If you get 3 you have system/domain/user. Extract just the parts you want. String.Split works well for this.


    Michael Taylor http://www.michaeltaylorp3.net

    Monday, January 21, 2019 6:14 PM
    Moderator
  • Please could you help me .

    Why it is failing to get the DomainName and UserName from the managementObjectCollection , When user logged-in with Microsoft credentials.

    Tuesday, January 22, 2019 7:10 AM
  • Hi DeepakHirapur,

    Thank you for posting here.

    Based on your description, you want to get the username and domain name from ManagementObjectCollection in right format.

    I write a code example for it. it works in win10,but it does not work in win8.1.

    So I suggest you could try the following code to get username and domain name with other ways.

                string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;//first way
                string username = Environment.UserDomainName + "\\" +Environment.UserName;//second way
    

    Hope my advice could be helpful.

    Best regards,

    Jack



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 22, 2019 7:56 AM
    Moderator
  • It's not failing to get the information. You said it is returning the information but with the machine name added. That is the behavior. Are you not able to get the info you need from that? If not then please post the code that you're using.

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, January 22, 2019 2:48 PM
    Moderator
  • Thank you for Suggestions

    These two statements are helpful to get the process user name Not Current logged in User name.

    Application is installed in Non Admin User account If the application is launched with run as administrator ,it is returning the admin details.

    It should return the Current logged-in user. 


    Wednesday, April 10, 2019 7:05 AM