Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 使用WINAPI查找特殊文件上的进程活动句柄(锁)_Windows_Go_Winapi - Fatal编程技术网

Windows 使用WINAPI查找特殊文件上的进程活动句柄(锁)

Windows 使用WINAPI查找特殊文件上的进程活动句柄(锁),windows,go,winapi,Windows,Go,Winapi,我想使用此资源通过使用Windows API(重置管理器)编写与Go for Windows相同的内容 到目前为止,我的代码是 Rstrtmgr := syscall.NewLazyDLL("Rstrtmgr.dll") RmStartSession := Rstrtmgr.NewProc("RmStartSession") RmRegisterResources := Rstrtmgr.NewProc("RmRegisterResources") RmGetList := Rstrtmgr.N

我想使用此资源通过使用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,通过路径锁定我的文件

我编辑我的代码。请复习一下

  • 举例

RmRegisterResources
需要一个rgsFileNames,这意味着文件名字符串的指针您可以传递字符串数组,或者如果只需要处理一个特殊文件,只需传递文件名字符串的地址即可

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)

我在研究问题时创建了一个。它还包括错误输出,但看起来不像“正常恐慌”。@xarantolus感谢听到有人关心它,但我们如何解决它?@xarantolus可能RmRegisterResources的args 3应该是字符串数组而不是字符串Hi,这解决了您的问题吗?请记住标记这是否回答了您的问题,或者你也可以添加一个答案,这是你可以得到的。谢谢先生,解决我的问题第一阶段。下一阶段呢@吴德雷克