none
"access denied" for Process.GetProcessesByName RRS feed

  • Question

  • Hello,

    I have an application which is in C# & i want to call user defined service(which is developed in VC++).I am calling this service using "Process" class. This application is run under Local System account by default. It can get other processes using Process.GetProcessesByName(). But invoking GetProcessesByName() method throws Win32Exception saying that access is denied. I have tried all the solutions I have found in the Internet, but no luck. How could I remedy this?

    I tried to grant permission to service/process using microsoft "subinacl" tool as well, but no luck

    Process[] localByName = Process.GetProcessesByName("770FieldbusService");
    access denied - StackTrace
       at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 access, Boolean throwIfExited)
       at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId, Boolean firstModuleOnly)
       at System.Diagnostics.NtProcessManager.GetFirstModuleInfo(Int32 processId)
       at System.Diagnostics.Process.get_MainModule()
       at Emerson.FoundationFieldbus.Cfg770.Get770ServerFilePath() in D:\Projects\USBFF_Config770\Config770\API_FieldBus\Cfg770.cs:line 514

    Regards,

    Shilpa

    Wednesday, December 11, 2013 9:05 AM

Answers

  • Hi Shilpab,

    Yes you can. Please see the steps on the following link. http://stackoverflow.com/questions/10850595/windows-service-start-and-stop-without-admin-privileges.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by shilpab Friday, December 20, 2013 6:11 AM
    Wednesday, December 18, 2013 5:38 AM
    Moderator
  • Hi Hetro,

    Issue got resolved with "ServiceController" class in c#.

    I have started & stop my service as below & it is working fine for non admin user as well:

    sc start 770foeldbusservice

    sc stop 770fieldbusservice

    Thanks for your help.

    Regards,

    Shilpa

    • Marked as answer by shilpab Friday, December 20, 2013 6:12 AM
    Friday, December 20, 2013 6:10 AM

All replies

  • Hi Shilpab,

    You should work with non-elevated process to work around this issue. See the following blog to know how to do it.

    http://www.aboutmycode.com/net-framework/how-to-get-elevated-process-path-in-net/.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 12, 2013 5:41 AM
    Moderator
  • Hi Hetro,

    Thanks for your reply. I was knowing this solution but it is for vista or above vista.I am running on windows XP.It is giving error for "ProcessAccessFlags" class on XP. Again i don't need only path but want to execure that service as well. For that i am getting following error.

    _exceptionMethod = {Microsoft.Win32.SafeHandles.SafeProcessHandle OpenProcess(Int32, Int32, Boolean)}

    I went through below site.I want to execute execute all things related to "process" class for non elevated user.

    http://www.aboutmycode.com/net/access-denied-process-bugs/

    Regards,

    Shilpa

    Friday, December 13, 2013 9:27 AM
  • Hi Hetro,

    Even i wanted to start that process.My code looks as below:

     Process HseSProcess = new Process();
     HseSProcess.StartInfo.WindowStyle =   ProcessWindowStyle.Hidden;
            HseSProcess.StartInfo.FileName = filename;          
            HseSProcess.StartInfo.Arguments = cmd;
           
            HseSProcess.Start();
            // wait util the process exited
            HseSProcess.WaitForExit();
            HseSProcess.Dispose();

    I tried to give permission using "subinacl" tool.Now i am not getting any exception at "HseProcess.Start()" but in actual process is not getting started.

    Regards,

    Shilpa

    Friday, December 13, 2013 9:42 AM
  • Hi Shilpab,

    > i want to call user defined service (which is developed in VC++).

    Did you mean call a windows service using process class? If so, I think you cannot do this. Because service don’t have a desktop associated with them. Windows services are not designed to run interactive applications. You need to rethink your design and use something other than a windows service.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 16, 2013 5:49 AM
    Moderator
  • Hi Hetro,

    Thanks for prompt reply & suggestion.

    That service is developed by me in VC++ which is acting as a server. We can start/stop this service.

    E.g.

    string filename=@"c:\Program Files\USB Fieldbus Interface\Service\

    770FieldbusService.exe";

    HseSProcess.StartInfo.FileName = filename;     

    "770FieldbusService.exe"    nothing bus it is service developed in VC++ which we can start  & stop as below:

    Start service:

    770FieldbusService.exe -s

    Stop Service:

    770FieldbusService.exe -k

    Can I do this with non admin privileges or it is not possible?

    Regards,

    Shilpa

    Tuesday, December 17, 2013 2:20 PM
  • Hi Shilpab,

    Yes you can. Please see the steps on the following link. http://stackoverflow.com/questions/10850595/windows-service-start-and-stop-without-admin-privileges.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by shilpab Friday, December 20, 2013 6:11 AM
    Wednesday, December 18, 2013 5:38 AM
    Moderator
  • Hi Hetro,

    Thanks a lot for your reply.I followed "SUBINACL" tool option from you suggested link.I already tried that.

    With this tool,i am able to give privilege to regisry key & it is working fine.For service,i am able to give rights but it is not working for non privilege user.

    E.g. From administartor account i tried as below:

    1. subinacl /keyreg "HKEY_LOCAL_MACHINE\SYSTEM" /grant=users=f /grant=everyone=f

    This is working fine for non privilege user as well.

    2. SUBINACL /SERVICE 770FieldbusService.exe /GRANT=Users=TOP

    This is able to grant privilege but still i am not able to start/stop service.

    My service is NT Service.

    Regards,

    Shilpa

    Thursday, December 19, 2013 10:02 AM
  • Hetro,

    This NT Service implemented by some else.i was walking through the code & came to know it is NT service. So if i am not wrong then it is windows servcie.

    As you already told that if it is windows service then we can't do this right?Then only option available is to start sercvice with admin privilege.

    Regards,

    Shilpa

    Thursday, December 19, 2013 10:07 AM
  • Hi Hetro,

    Issue got resolved with "ServiceController" class in c#.

    I have started & stop my service as below & it is working fine for non admin user as well:

    sc start 770foeldbusservice

    sc stop 770fieldbusservice

    Thanks for your help.

    Regards,

    Shilpa

    • Marked as answer by shilpab Friday, December 20, 2013 6:12 AM
    Friday, December 20, 2013 6:10 AM