none
Pocess.StartInfo.UserName is returning Empty RRS feed

  • Question

  • Hi,

    I need to check if Outlook is started by the current logged in user or not.

    For this I have written the below code:

    const string outlookProcessName = "OUTLOOK";
    IEnumerable<string> ownerName = Process.GetProcessesByName(outlookProcessName).Select(x => x.StartInfo.UserName).ToList();

    However, the ownerName is empty.

    Require your assistance in getting the user


    Monday, May 26, 2014 11:30 AM

Answers

  • Thanks Viorel for the suggesting WMI, before posting here, I had a look at WMI, however I thought without using WMI there might be a possibility.

    I used the following code to figure out if outlook is running for the currently logged in user:

    private static bool IsOutlookRunning()
    {
    	const string outlookProcessName = "OUTLOOK";
            Process[] runningProcesses = Process.GetProcessesByName(outlookProcessName);
    
    	var currentSessionId = Process.GetCurrentProcess().SessionId;
            int sameAsthisSessionCount = (from c in runningProcesses where c.SessionId == currentSessionId select c).Count();
            return sameAsthisSessionCount > 0;
    }
    Wednesday, May 28, 2014 6:51 AM

All replies

  • Look in task manager and check which letters in OUTLOOK are uppercase and lowercase.  The search is case sensitive and you must exactly match the actual process name.

    jdweng

    Monday, May 26, 2014 12:16 PM
  • Hi Joel,

    In task manager it is showing as "OUTLOOK.EXE *32". I have tried "OUTLOOK.EXE", "OUTLOOK.EXE *32" and these gave me error where as "OUTLOOK.EXE" did not give me error nor the intended result(i.e. the user name).

    FYI, I am using .net 4.0.

    Tuesday, May 27, 2014 5:32 AM
  • There is a series of articles that recommend Windows Management Instrumentation (WMI):

    So get the process ID using Process class, then find the Win32_Process object and call GetOwner as shown in examples.



    • Edited by Viorel_MVP Tuesday, May 27, 2014 5:46 AM
    Tuesday, May 27, 2014 5:45 AM
  • Look at the details tab in task manager for the name.  The tab should contain the .exe names.

    jdweng

    Tuesday, May 27, 2014 8:09 AM
  • Thanks Viorel for the suggesting WMI, before posting here, I had a look at WMI, however I thought without using WMI there might be a possibility.

    I used the following code to figure out if outlook is running for the currently logged in user:

    private static bool IsOutlookRunning()
    {
    	const string outlookProcessName = "OUTLOOK";
            Process[] runningProcesses = Process.GetProcessesByName(outlookProcessName);
    
    	var currentSessionId = Process.GetCurrentProcess().SessionId;
            int sameAsthisSessionCount = (from c in runningProcesses where c.SessionId == currentSessionId select c).Count();
            return sameAsthisSessionCount > 0;
    }
    Wednesday, May 28, 2014 6:51 AM