当前位置: 首页>>代码示例>>C#>>正文


C# NamedPipeServerStream.GetImpersonationUserName方法代码示例

本文整理汇总了C#中System.IO.Pipes.NamedPipeServerStream.GetImpersonationUserName方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeServerStream.GetImpersonationUserName方法的具体用法?C# NamedPipeServerStream.GetImpersonationUserName怎么用?C# NamedPipeServerStream.GetImpersonationUserName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Pipes.NamedPipeServerStream的用法示例。


在下文中一共展示了NamedPipeServerStream.GetImpersonationUserName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ServerThread

    private static void ServerThread(object data)
    {
        NamedPipeServerStream pipeServer =
            new NamedPipeServerStream("testpipe", PipeDirection.InOut, numThreads);

        int threadId = Thread.CurrentThread.ManagedThreadId;

        // Wait for a client to connect
        pipeServer.WaitForConnection();

        Console.WriteLine("Client connected on thread[{0}].", threadId);
        try
        {
            // Read the request from the client. Once the client has
            // written to the pipe its security token will be available.

            StreamString ss = new StreamString(pipeServer);

            // Verify our identity to the connected client using a
            // string that the client anticipates.

            ss.WriteString("I am the one true server!");
            string filename = ss.ReadString();

            // Read in the contents of the file while impersonating the client.
            ReadFileToStream fileReader = new ReadFileToStream(ss, filename);

            // Display the name of the user we are impersonating.
            Console.WriteLine("Reading file: {0} on thread[{1}] as user: {2}.",
                filename, threadId, pipeServer.GetImpersonationUserName());
            pipeServer.RunAsClient(fileReader.Start);
        }
        // Catch the IOException that is raised if the pipe is broken
        // or disconnected.
        catch (IOException e)
        {
            Console.WriteLine("ERROR: {0}", e.Message);
        }
        pipeServer.Close();
    }
开发者ID:retracy,项目名称:pipes,代码行数:40,代码来源:Program.cs

示例2: ServerThread

    private static void ServerThread(object data)
    {
        NamedPipeServerStream pipeServer =
            new NamedPipeServerStream("testpipe", PipeDirection.InOut, numThreads);
        int threadId = Thread.CurrentThread.ManagedThreadId;

        //wait for client to connect
        pipeServer.WaitForConnection();

        Console.WriteLine("Client connected on thread[{0}].", threadId);
        try
        {
            //Read the request from the client. Once the client has
            //written to the pipe its security token will be available.
            //We might not need this security token ? 
            //We need interprocess communication on the same computer
            StreamString ss = new StreamString(pipeServer);

            //Verify our identity to the connected client using a 
            //string that the client anticipates

            ss.WriteString("I am the one true server!");
            string filename = ss.ReadString();

            //Read in the contents of the file while impersonating the client.
            ReadFileToStream fileReader = new ReadFileToStream(ss, filename);

            //Display the name of the user we are impersonating. //Impersonating ? 
            Console.WriteLine("Reading file: {0} on thread{1} as user: {2}.",
                filename, threadId, pipeServer.GetImpersonationUserName()); //So impersonation is nothing but name of client at the other end ? Cool!
            pipeServer.RunAsClient(fileReader.Start);
        }
        catch(IOException e)
        {
            Console.WriteLine("ERROR: {0}", e.Message);
        }
        pipeServer.Close();
    }
开发者ID:eaglespy21,项目名称:NamedPipeServer,代码行数:38,代码来源:Program.cs

示例3: ServerThread

        private static void ServerThread(object data)
        {
            var pipeServer = new NamedPipeServerStream("testpipe", PipeDirection.InOut, numThreads);
            int threadId = Thread.CurrentThread.ManagedThreadId;

            pipeServer.WaitForConnection();

            Console.WriteLine("Client connected on thread[{0}].", threadId);
            try
            {
                StreamString ss = new StreamString(pipeServer);
                ss.WriteString("I am the one true server!");
                string filename = ss.ReadString();
                ReadFileToStream fileReader = new ReadFileToStream(ss, filename);
                Console.WriteLine("Reading file: {0} on thread[{1}] as user: {2}.",
                    filename, threadId, pipeServer.GetImpersonationUserName());
                pipeServer.RunAsClient(fileReader.Start);
            }
            catch (IOException e)
            {
                Console.WriteLine("ERROR: {0}", e.Message);
            }
            pipeServer.Close();
        }
开发者ID:JianchengZh,项目名称:kasicass,代码行数:24,代码来源:PipeServer.cs

示例4: ServerThread

        public void ServerThread()
        {
            NamedPipeServerStream pipeServer = new NamedPipeServerStream("FTPbox Server", PipeDirection.InOut, 5);
            int threadID = Thread.CurrentThread.ManagedThreadId;

            pipeServer.WaitForConnection();

            Log.Write(l.Client, "Client connected, id: {0}", threadID);

            try
            {
                StreamString ss = new StreamString(pipeServer);

                ss.WriteString("ftpbox");
                string args = ss.ReadString();

                ReadMessageSent fReader = new ReadMessageSent(ss, "All done!");

                Log.Write(l.Client, "Reading file: \n {0} \non thread [{1}] as user {2}.", args, threadID, pipeServer.GetImpersonationUserName());

                List<string> li = new List<string>();
                li = ReadCombinedParameters(args);

                CheckClientArgs(li.ToArray());

                pipeServer.RunAsClient(fReader.Start);
            }
            catch (IOException e)
            {
                Common.LogError(e);
            }
            pipeServer.Close();
        }
开发者ID:skopp,项目名称:FTPbox,代码行数:33,代码来源:fMain.cs

示例5: ClientServerMessages

    public static void ClientServerMessages()
    {
        byte[] msg1 = new byte[] { 5, 7, 9, 10 };
        byte[] msg2 = new byte[] { 2, 4 };
        byte[] received1 = new byte[] { 0, 0, 0, 0 };
        byte[] received2 = new byte[] { 0, 0 };
        byte[] received3 = new byte[] { 0, 0, 0, 0}; ;

        using (NamedPipeServerStream server = new NamedPipeServerStream("foomsg", PipeDirection.InOut, 1, PipeTransmissionMode.Message))
        {
            using (NamedPipeClientStream client = new NamedPipeClientStream(".", "foomsg", PipeDirection.InOut, PipeOptions.None, System.Security.Principal.TokenImpersonationLevel.Identification))
            {
                Task clientTask = Task.Run(() =>
                {
                    client.Connect();
                    
                    client.Write(msg1, 0, msg1.Length);
                    client.Write(msg2, 0, msg2.Length);
                    client.Write(msg1, 0, msg1.Length);

                    int serverCount = client.NumberOfServerInstances;
                    Assert.Equal(1, serverCount);
                });

                server.WaitForConnection();
                int len1 = server.Read(received1, 0, msg1.Length);
                Assert.True(server.IsMessageComplete);
                Assert.Equal(msg1.Length, len1);
                Assert.Equal(msg1, received1);

                int len2 = server.Read(received2, 0, msg2.Length);
                Assert.True(server.IsMessageComplete);
                Assert.Equal(msg2.Length, len2);
                Assert.Equal(msg2, received2);

                int len3 = server.Read(received3, 0, msg1.Length - 1);  // read one less than message
                Assert.False(server.IsMessageComplete);
                Assert.Equal(msg1.Length - 1, len3);

                int len4 = server.Read(received3, len3, received3.Length - len3);
                Assert.True(server.IsMessageComplete);
                Assert.Equal(msg1.Length, len3 + len4);
                Assert.Equal(msg1, received3);

                string userName = server.GetImpersonationUserName();    // not sure what to test here that will work in all cases
            }
        }
    }
开发者ID:nuskarthik,项目名称:corefx,代码行数:48,代码来源:NamedPipesSimpleTest.cs

示例6: ServerThread

        private static void ServerThread(object data)
        {
            PipeSecurity ps = new PipeSecurity();
            ps.AddAccessRule(new PipeAccessRule("IIS_IUSRS", PipeAccessRights.ReadWrite, AccessControlType.Allow));
            ps.AddAccessRule(new PipeAccessRule(WindowsIdentity.GetCurrent().Owner, PipeAccessRights.FullControl, AccessControlType.Allow));
            using (NamedPipeServerStream pipeServer =
                new NamedPipeServerStream(RemoteDemoControlPipe.PIPE_NAME, PipeDirection.InOut, numThreads, PipeTransmissionMode.Message, PipeOptions.WriteThrough, 1024, 1024, ps))
            {

                int threadId = Thread.CurrentThread.ManagedThreadId;

                Console.WriteLine("Created thread[{0}].", threadId);

                // Wait for a client to connect
                pipeServer.WaitForConnection();

                Console.WriteLine("Client connected on thread[{0}].", threadId);
                try
                {
                    // Read the request from the client. Once the client has
                    // written to the pipe its security token will be available.

                    StreamString ss = new StreamString(pipeServer);

                    // Verify our identity to the connected client using a
                    // string that the client anticipates.

                    ss.WriteString(RemoteDemoControlPipe.PIPE_SIGNATURE);
                    string filename = ss.ReadString();

                    if (WorkstationLockedUtil.IsWorkstationLocked())
                    {
                        ss.WriteString("Workstation is locked. Scripts can not be run.");
                    }
                    else
                    {
                        // Display the name of the user we are impersonating.
                        Console.WriteLine("Launching script: {0} on thread[{1}] as user: {2}.",
                            filename, threadId, pipeServer.GetImpersonationUserName());

                        // Launch the specified script
                        System.Diagnostics.Process proc = new System.Diagnostics.Process();

                        proc.StartInfo.UseShellExecute = false;

                        if (File.Exists(filename))
                        {
                            Process.Start(filename);
                            ss.WriteString("Process started: " + filename);
                        }
                        else
                        {
                            ss.WriteString("File does not exist: " + filename);
                        }
                    }
                }
                // Catch the IOException that is raised if the pipe is broken
                // or disconnected.
                catch (IOException e)
                {
                    Console.WriteLine("ERROR: {0}", e.Message);
                }
                pipeServer.Close();
            }
        }
开发者ID:sgilroy,项目名称:RemoteDemoControl,代码行数:65,代码来源:DemoLaunchingServer.cs


注:本文中的System.IO.Pipes.NamedPipeServerStream.GetImpersonationUserName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。