gpt4 book ai didi

windows - 使用WINAPI找出特殊文件上的进程事件句柄(锁定)

转载 作者:行者123 更新时间:2023-12-01 22:27:53 27 4
gpt4 key购买 nike

我想使用此script作为资源,通过使用Windows API(重置管理器)与Go for Windows中的内容相同

到目前为止,我的代码是

Rstrtmgr := syscall.NewLazyDLL("Rstrtmgr.dll")
RmStartSession := Rstrtmgr.NewProc("RmStartSession")
RmRegisterResources := Rstrtmgr.NewProc("RmRegisterResources")
RmGetList := Rstrtmgr.NewProc("RmGetList")

var dwSession uint32 = 0
var szSessionKey = Utils.RandString(32)
ret, _, callErr := RmStartSession.Call(
uintptr(unsafe.Pointer(&dwSession)),
uintptr(0),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(szSessionKey))))


var rgsFileNames = unsafe.Pointer(syscall.StringToUTF16Ptr(szPath))
ret, _, callErr = RmRegisterResources.Call(
uintptr(dwSession),
uintptr(1),
uintptr(unsafe.Pointer(&rgsFileNames)),
uintptr(0),
uintptr(unsafe.Pointer(nil)),
uintptr(0),
uintptr(unsafe.Pointer(nil)))


var nProcInfoNeeded uint32 = 0
var nProcInfo uint32 = 10
var lpdwRebootReasons uint32 = 0

type RM_UNIQUE_PROCESS struct {
dwProcessId uint32
ProcessStartTime windows.Filetime
}

type ApplicationType struct {
RmUnknownApp uint32
RmMainWindow uint32
RmOtherWindow uint32
RmService uint32
RmExplorer uint32
RmConsole uint32
RmCritical uint32
}

type RM_PROCESS_INFO struct{
RM_UNIQUE_PROCESS RM_UNIQUE_PROCESS
strAppName string
strServiceShortName string
RM_APP_TYPE ApplicationType
AppStatus uint32
TSSessionId uint32
bRestartable bool
}

var _RM_PROCESS_INFO [10]RM_PROCESS_INFO
ret, _, callErr = RmGetList.Call(
uintptr(dwSession),
uintptr(unsafe.Pointer(&nProcInfoNeeded)),
uintptr(unsafe.Pointer(&nProcInfo)),
uintptr(unsafe.Pointer(&_RM_PROCESS_INFO)),
uintptr(unsafe.Pointer(&lpdwRebootReasons)),
)
_ = ret
_ = callErr

但是我在RmGetList上有错误

我的目标是获取该进程的PID,按路径锁定我的文件

我编辑我的代码。请检查一下

c++中的
  • 示例
  • 最佳答案

    RmRegisterResources需要一个rgsFileName s ,这表示文件名字符串的指针,您可以传递字符串数组,如果只需要处理一个特殊文件,则只需传递文件名字符串的地址即可。

    var rgsFileNames = unsafe.Pointer(syscall.StringToUTF16Ptr(szPath));
    ret, _, callErr = syscall.Syscall9(RmRegisterResources,
    7,
    uintptr(dwSession),
    uintptr(1),
    uintptr(unsafe.Pointer(&rgsFileNames)),
    uintptr(0),
    uintptr(unsafe.Pointer(nil)),
    uintptr(0),
    uintptr(unsafe.Pointer(nil)),
    0,
    0)

    关于windows - 使用WINAPI找出特殊文件上的进程事件句柄(锁定),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58781818/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com