我想使用此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(unsafe.Pointer(nil)),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++中的示例