Exemplo n.º 1
0
        public Process InitializeProcessWithChagedSession(string filename, string arguments, bool interactive, Dictionary <string, string> extraEnvironmentVariables)
        {
            string tempSeriviceId = Guid.NewGuid().ToString();

            InitChangeSessionService(tempSeriviceId);

            var bind = new NetNamedPipeBinding();

            bind.Security.Mode = NetNamedPipeSecurityMode.Transport;
            bind.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;

            var endpoint = new EndpointAddress(changeSessionBaseEndpointAddress + "/" + tempSeriviceId);

            var channelFactory = new ChannelFactory <IExecutor>(bind, endpoint);

            IExecutor remoteSessionExec = channelFactory.CreateChannel();

            var workingProcessId = remoteSessionExec.ExecuteProcess(this, filename, arguments, extraEnvironmentVariables);
            var workingProcess   = Process.GetProcessById(workingProcessId);

            workingProcess.EnableRaisingEvents = true;

            CloseRemoteSession(remoteSessionExec);

            ResumeProcess(workingProcess);

            RemoveChangeSessionService(tempSeriviceId);

            return(workingProcess);
        }