none
Getting Process Owner Name on Windows RRS feed

  • Question

  • Hello , 

    I want to get the process owner name on machine . I am using the below code 

                        

    string query = "Select * From Win32_Process Where ProcessID = " + 20636;
                    ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
                    ManagementObjectCollection processList = searcher.Get();

                    foreach (ManagementObject process in processList)
                    {
                        string[] argList = new string[] { string.Empty, string.Empty };
                        int returnVal = Convert.ToInt32(process.InvokeMethod("GetOwner", argList));

                    }

    Above code works fine when Visual Studio is running in Admin Mode . However in Non-Admin mode , returnValue is 2 and arglist is empty.

    Is there a solution to get process owner name in Non Admin Mode.


    Kapil Gupta

    Monday, February 19, 2018 10:19 AM

All replies

  • A process running under a standard user account does not have sufficient privilege to obtain the desired information from all other processes.  This is just a result of the standard Windows security mechanisms.
    Monday, February 19, 2018 12:00 PM
  • Hi KapGup,

    The Admin Mode would have more permission to get the information than user Mode.

    If you want to run the VS as Admin by default, you could try to set the requestedExecutionLevel in your manifest file.

    Right Click your project> Security> Select Enable ClickOnce Security Settings. Then you could find app.manifest file in your project properties.

    change 

    <requestedExecutionLevel level="asInvoker" uiAccess="false"/>

    to

    <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>

    Best Regards,

    Wendy


    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.


    Sunday, February 25, 2018 5:27 PM
    Moderator