System.ComponentModel.Win32Exception: Access is denied in SuperSocket

0

I am working on a windows service application on .NET framework. The application runs smoothly for a single windows user and at first, i didn't consider that there could be multiple windows users on a single machine and they could want separate instances of that application running for their use. So when a user switches his windows account to another, the logged in user will get an instance of the application service running properly for his environment.

So for multiple windows users, i want to allow multiple instances of the application. But the problem is, only the first instance of the application works properly. But the following instances (created later on) on the other windows users produces this error. The processes are running but the access is denied when it tries to initialize.

System.ComponentModel.Win32Exception (0x80004005): Access is denied
   at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfExited)
   at System.Diagnostics.Process.OpenProcessHandle(Int32 access)
   at System.Diagnostics.Process.set_EnableRaisingEvents(Boolean value)
   at SuperSocket.SocketEngine.ProcessPerformanceCounterHelper.RegisterSameNameProcesses(Process process)
   at SuperSocket.SocketEngine.ProcessPerformanceCounterHelper..ctor(Process process)
   at SuperSocket.SocketEngine.PerformanceMonitor..ctor(IRootConfig config, IEnumerable`1 appServers, IWorkItem serverManager, ILogFactory logFactory)
   at SuperSocket.SocketEngine.DefaultBootstrap.Initialize(Func`2 serverConfigResolver, ILogFactory logFactory)
   at SuperSocket.SocketEngine.DefaultBootstrap.Initialize(Func`2 serverConfigResolver)
   at SuperSocket.SocketEngine.DefaultBootstrap.Initialize()

Scenario-01: If i exit the service from User A and then switch to User B. Then the service runs nicely in User B.

Scenario-02: If i don't exit the service from User A and then switched to User B. Then the process runs but the service can not be started.

Scenario-03: If i directly log into User B, then the service starts without any problem.

After debugging, i found the above exception is thrown in the bootstrap.Start() line.

class DenticonAppServer
{
    IBootstrap bootstrap;        
    log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    public DenticonAppServer()
    {
        log.Debug("Socket instance Created!\n");
        log4net.Config.XmlConfigurator.Configure();
    }

    private bool Initialize()
    {
        bootstrap = BootstrapFactory.CreateBootstrap();
        if (!bootstrap.Initialize())
        {
            log.Debug("Failed to initialize Bootstrap!\n");
            return false;
        }

        log.Debug("Bootstrap Initialized!\n");
        return true;
    }

    public void Start()
    {
        if (bootstrap == null)
        {
            if (Initialize() == false)
            {
                return;
            }
        }
        var result = bootstrap.Start();

        if (result == StartResult.Failed)
        {
            log.Debug("Failed to start Bootstrap!\n");
            return;
        }
        log.Debug("Bootstrap Started!\n");
    }

    public void Stop()
    {
        bootstrap.Stop();
        log.Debug("Bootstrap Stopped!\n");
    }
}

How to resolve this access denied error?

Thanks in advance.

windows
windows-services
supersocket.net

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0