【发布时间】:2021-01-19 17:35:46
【问题描述】:
我想使用这个 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++ 中的示例
【问题讨论】:
-
我在调查问题时创建了this example。它还包括错误输出,但看起来不像“正常恐慌”。
-
@xarantolus 感谢听到有人关心它,但我们该如何解决?
-
@xarantolus 可能 RmRegisterResources 的参数 3 应该是字符串数组而不是字符串 docs.microsoft.com/en-us/windows/win32/api/restartmanager/…