如何解决C# - CreateProcess API 在用于生成任务管理器时返回 740
我正在尝试使用 CreateProcess API 从 C# 生成任务管理器。
不幸的是,我总是从 CreateProcess 得到代码 740,有点谷歌搜索,代码 740 是:ERROR_ELEVATION_required
。
我使用的创建标志是 CreateSuspended、CreateDetachedProcess、CreateNowindow 和 CreateUnicodeEnvironment(以防万一我的父进程在 lpEnvironment 上有 Unicode)。正常情况下,任务管理器不需要管理员权限吧?
这是我使用的代码:
[StructLayout(LayoutKind.Sequential)]
public struct STARTUPINFO
{
public uint cb;
public IntPtr lpReserved;
public IntPtr lpDesktop;
public IntPtr lpTitle;
public uint dwX;
public uint dwY;
public uint dwXSize;
public uint dwYSize;
public uint dwXCountChars;
public uint dwYCountChars;
public uint dwFillAttributes;
public uint dwFlags;
public ushort wShowWindow;
public ushort cbReserved;
public IntPtr lpReserved2;
public IntPtr hStdInput;
public IntPtr hStdOutput;
public IntPtr hStdErr;
}
[StructLayout(LayoutKind.Sequential)]
public struct STARTUPINFOEX
{
public STARTUPINFO StartupInfo;
public IntPtr lpAttributeList;
}
[StructLayout(LayoutKind.Sequential)]
public struct PROCESS_informatION
{
public IntPtr hProcess;
public IntPtr hThread;
public int dwProcessId;
public int dwThreadId;
}
[StructLayout(LayoutKind.Sequential)]
public struct Security_ATTRIBUTES
{
public int nLength;
public IntPtr lpSecurityDescriptor;
public int bInheritHandle;
}
[Flags]
public enum CreationFlags
{
CreateSuspended = 0x00000004,DetachedProcess = 0x00000008,CreateNowindow = 0x08000000,CreateUnicodeEnv = 0x00000400
}
[DllImport("kernel32.dll",SetLastError = true)]
public static extern bool CreateProcess(string lpApplicationName,string lpCommandLine,ref Security_ATTRIBUTES lpProcessAttributes,ref Security_ATTRIBUTES lpThreadAttributes,bool bInheritHandles,CreationFlags dwCreationFlags,IntPtr lpEnvironment,string lpCurrentDirectory,[In] ref STARTUPINFOEX lpStartupInfo,out PROCESS_informatION lpProcessinformation);
public static void Main() {
string PathToExecutableForProcess = @"C:\Windows\System32\Taskmgr.exe";
STARTUPINFOEX sInfoEx = new STARTUPINFOEX();
PROCESS_informatION pInfo = new PROCESS_informatION();
sInfoEx.StartupInfo.cb = (uint)Marshal.SizeOf(sInfoEx);
IntPtr lpValue = IntPtr.Zero;
Security_ATTRIBUTES pSec = new Security_ATTRIBUTES();
Security_ATTRIBUTES tSec = new Security_ATTRIBUTES();
pSec.nLength = Marshal.SizeOf(pSec);
tSec.nLength = Marshal.SizeOf(tSec);
CreationFlags flags = CreationFlags.CreateSuspended | CreationFlags.DetachedProcess | CreationFlags.CreateNowindow | CreationFlags.CreateUnicodeEnv;
// spawn the new process
bool CreateProcessResult = CreateProcess(PathToExecutableForProcess,null,ref pSec,ref tSec,false,flags,(IntPtr)0,ref sInfoEx,out pInfo);
if (CreateProcessResult) {
Console.WriteLine("[+] {0}'s process spawned!",PathToExecutableForProcess);
}else {
Console.WriteLine("[-] Failed to spawn the new process because of code {0}!",(Marshal.GetLastWin32Error()));
}
}
有人知道如何解决这个问题吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。