【C#】OpenProcess 返回 IntPtr 是0的问题
为了方面各位大侠解答我特意搞了个控制台程序代码如下usingSystem;usingSystem.Collections.Generic;usingSystem.Text...
为了方面各位大侠解答 我特意搞了个控制台程序 代码如下
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace ConsoleApplication1
{
//打开不安全代码开关:项目-右键-属性-生成-允许不安全代码
class Program
{
[DllImport("kernel32.dll")]
public static extern long OpenProcess(UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32 dwProcessId);
[DllImport("kernel32.dll",EntryPoint="OpenProcess")]
public static extern IntPtr OpenProcessPtr(UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32 dwProcessId);
[DllImport("ntdll.dll")]
public static extern long RtlAdjustPrivilege(long Privilege, long Enable, long CurrentThread, long Enabled);
[DllImport("kernel32.dll")] //GetLastError function
public static extern UInt32 GetLastError();
static void Main(string[] args)
{
Console.WriteLine("提升权限");
RtlAdjustPrivilege(0x14, 1, 0, 0); //提升权限
Console.WriteLine("提升权限:"+GetLastError().ToString());
Process[] MyProcess = Process.GetProcessesByName("War3");//War3
Console.WriteLine("读取进程ID:" + MyProcess[0].Id.ToString());
//(UInt32)lpdw;
long long_phandle= OpenProcess(0xFFF, 0, (UInt32)MyProcess[0].Id);//0xFFF
Console.WriteLine("读取句柄[long]:" + long_phandle.ToString());
IntPtr inptr = OpenProcessPtr(0xFFF, 0, (UInt32)MyProcess[0].Id);
Console.WriteLine("读取句柄[inptr]:" + inptr.ToString());
Console.Read();
}
}
}
我测试过其它的进程都可以取到但就是当是 War3的时候就取到0【War3是魔兽争霸冰封王座(1.2e)】
希望各位大侠不吝赐教。先行谢过
附图是我的执行结果
补充图 展开
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace ConsoleApplication1
{
//打开不安全代码开关:项目-右键-属性-生成-允许不安全代码
class Program
{
[DllImport("kernel32.dll")]
public static extern long OpenProcess(UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32 dwProcessId);
[DllImport("kernel32.dll",EntryPoint="OpenProcess")]
public static extern IntPtr OpenProcessPtr(UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32 dwProcessId);
[DllImport("ntdll.dll")]
public static extern long RtlAdjustPrivilege(long Privilege, long Enable, long CurrentThread, long Enabled);
[DllImport("kernel32.dll")] //GetLastError function
public static extern UInt32 GetLastError();
static void Main(string[] args)
{
Console.WriteLine("提升权限");
RtlAdjustPrivilege(0x14, 1, 0, 0); //提升权限
Console.WriteLine("提升权限:"+GetLastError().ToString());
Process[] MyProcess = Process.GetProcessesByName("War3");//War3
Console.WriteLine("读取进程ID:" + MyProcess[0].Id.ToString());
//(UInt32)lpdw;
long long_phandle= OpenProcess(0xFFF, 0, (UInt32)MyProcess[0].Id);//0xFFF
Console.WriteLine("读取句柄[long]:" + long_phandle.ToString());
IntPtr inptr = OpenProcessPtr(0xFFF, 0, (UInt32)MyProcess[0].Id);
Console.WriteLine("读取句柄[inptr]:" + inptr.ToString());
Console.Read();
}
}
}
我测试过其它的进程都可以取到但就是当是 War3的时候就取到0【War3是魔兽争霸冰封王座(1.2e)】
希望各位大侠不吝赐教。先行谢过
附图是我的执行结果
补充图 展开
1个回答
展开全部
貌似没有0xFFF吧
{
All = 0x001F0FFF,
Terminate = 0x00000001,
CreateThread = 0x00000002,
VMOperation = 0x00000008,
VMRead = 0x00000010,
VMWrite = 0x00000020,
DupHandle = 0x00000040,
SetInformation = 0x00000200,
QueryInformation = 0x00000400,
Synchronize = 0x00100000
}
{
All = 0x001F0FFF,
Terminate = 0x00000001,
CreateThread = 0x00000002,
VMOperation = 0x00000008,
VMRead = 0x00000010,
VMWrite = 0x00000020,
DupHandle = 0x00000040,
SetInformation = 0x00000200,
QueryInformation = 0x00000400,
Synchronize = 0x00100000
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询