简体   繁体   English

从 CreateProcessWithTokenW 获取 C# 中的进程对象

[英]Get a Process objet in C# from CreateProcessWithTokenW

For the need of my application i create a process with CreateProcessWithTokenW https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createprocesswithtokenw This help me run a process under the desktop user because my application is run under the Admin User为了我的应用程序的需要,我使用 CreateProcessWithTokenW 创建了一个进程https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createprocesswithtokenw这有助于我在桌面用户下运行一个进程,因为我的应用程序在管理员用户下运行

Before i use C# process to handle my process and get output ect...在我使用 C# 进程来处理我的进程并获得输出等之前...

How can i Get the process after create it with CreateProcessWithTokenW ?使用 CreateProcessWithTokenW 创建进程后如何获取进程? Their is some IntPtr in StartUPINFO that i get back but i don't find how to get the process with this.他们是我返回的 StartUPINFO 中的一些 IntPtr,但我没有找到如何使用此过程。

My struct is我的结构是

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        private struct STARTUPINFO
        {
            public Int32 cb;
            public string lpReserved;
            public string lpDesktop;
            public string lpTitle;
            public Int32 dwX;
            public Int32 dwY;
            public Int32 dwXSize;
            public Int32 dwYSize;
            public Int32 dwXCountChars;
            public Int32 dwYCountChars;
            public Int32 dwFillAttribute;
            public Int32 dwFlags;
            public Int16 wShowWindow;
            public Int16 cbReserved2;
            public IntPtr lpReserved2;
            public IntPtr hStdInput;
            public IntPtr hStdOutput;
            public IntPtr hStdError;
        }

i kinda understand i got some Ptr to ouput input ect... but i don't get how to get my process back any ideA?我有点明白我有一些 Ptr 来输出输入等......但我不知道如何让我的过程恢复任何想法?

I wasnt looking in the good place.我没有找好的地方。 Now y use the PROCESS_INFORMATION that my methode send back Inside their is a process Id that i can get back with this simple code现在你使用我的方法发回的 PROCESS_INFORMATION 在他们里面是一个进程 ID,我可以用这个简单的代码返回

var res = ProcessHelper.RunAsDesktopUser(fileName, opt);
var process = Process.GetProcessById(res.dwProcessId);

I have tested it and it work perfectly fine.我已经测试过它并且它工作得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM