public IEnumerable <ILockingProcessInfo> GetProcesses() { if (_registered) { var num = 0; var pnProcInfo = 0; RestartMgr.RmProcessInfo[] array = null; do { num = RestartMgr.RmGetList(_sessionId, out var pnProcInfoNeeded, ref pnProcInfo, array, out var _); switch (num) { case 234: pnProcInfo = pnProcInfoNeeded; array = new RestartMgr.RmProcessInfo[pnProcInfo]; continue; default: ThrowOnError(num); continue; case 0: break; } break; }while (num == 234); if (array != null && array.Length != 0) { return(array.Select(process => new LockingProcessInfo(process)).ToArray()); } } return(Enumerable.Empty <ILockingProcessInfo>()); }
public void Restart() { if (!_registered) { return; } ThrowOnError(RestartMgr.RmRestart(_sessionId, 0, null)); }
public void Shutdown(WindowsRestartManagerShutdown action = WindowsRestartManagerShutdown.ForceShutdown) { if (!_registered) { return; } ThrowOnError(RestartMgr.RmShutdown(_sessionId, action, null)); }
private void Dispose(bool disposing) { if (IsDisposed) { return; } var result = RestartMgr.RmEndSession(_sessionId); IsDisposed = true; ThrowOnError(result); }
public void Register(IEnumerable <string>?files = null, IEnumerable <ILockingProcessInfo>?processes = null) { var fileNames = files?.ToArray(); var fileCount = fileNames?.Length ?? 0; var processArray = processes?.ToArray(); var processCount = processArray?.Length ?? 0; if (fileCount == 0 && processCount == 0) { return; } _registered = true; var rgProcesses = processArray?.Select(Convert).ToArray(); ThrowOnError(RestartMgr.RmRegisterResources(_sessionId, fileCount, fileNames, processCount, rgProcesses, 0, null)); }