设置关键流程Ruby FFI
我是Windows API编程新手,曾经玩过Ruby FFI gem。 我对创建关键流程很好奇,下面是我的代码。 问题是,我一直收到Nope消息,这意味着进程没有设置为关键。我不知道这里出了什么问题 提前谢谢设置关键流程Ruby FFI,ruby,winapi,ffi,Ruby,Winapi,Ffi,我是Windows API编程新手,曾经玩过Ruby FFI gem。 我对创建关键流程很好奇,下面是我的代码。 问题是,我一直收到Nope消息,这意味着进程没有设置为关键。我不知道这里出了什么问题 提前谢谢 require 'ffi' module Win extend FFI::Library ffi_lib 'C:\Windows\System32\ntdll.dll' ffi_convention :stdcall attach_function :R
require 'ffi'
module Win
extend FFI::Library
ffi_lib 'C:\Windows\System32\ntdll.dll'
ffi_convention :stdcall
attach_function :RtlSetProcessIsCritical, [:int, :int, :int], :void
end
module Kernel
extend FFI::Library
ffi_lib 'kernel32'
ffi_convention :stdcall
attach_function :GetCurrentProcess, [], :pointer
attach_function :IsProcessCritical, [:pointer, :pointer], :int
end
begin
ptr = FFI::MemoryPointer.new :bool, 1
Win.RtlSetProcessIsCritical(1, 0, 0)
cprcs = Kernel.GetCurrentProcess()
Win.IsProcessCritical(cprcs, ptr)
if ptr.get(:bool, 0) then
puts "Critical"
else
puts "Nope."
end
rescue => e
puts e
ensure
Win.RtlSetProcessIsCritical(0, 0, 0)
end
发件人:
注意:使用此函数需要调用过程中的SE_DEBUG_NAME
权限。这可以通过使用
您需要至少拥有调试权限(可能更多)才能使流程成为关键流程。