public static List <LogInfo> RegHiveUnload(EngineState s, CodeCommand cmd) { List <LogInfo> logs = new List <LogInfo>(); CodeInfo_RegHiveUnload info = cmd.Info.Cast <CodeInfo_RegHiveUnload>(); string keyPath = StringEscaper.Preprocess(s, info.KeyPath); if (!_privilegesEnabled) { RegistryHelper.GetAdminPrivileges(); _privilegesEnabled = true; } int result = RegistryHelper.RegUnLoadKey(Registry.LocalMachine.Handle, keyPath); if (result == (int)BetterWin32Errors.Win32Error.ERROR_SUCCESS) { logs.Add(new LogInfo(LogState.Success, $"[HKLM\\{keyPath}] Unloaded")); } else { string errorMessage = new Win32Exception(result).Message; logs.Add(new LogInfo(LogState.Error, $"Could not unload [HKLM\\{keyPath}], error code = [{result} - {errorMessage}]")); } return(logs); }
public static List <LogInfo> RegHiveUnload(EngineState s, CodeCommand cmd) { List <LogInfo> logs = new List <LogInfo>(); Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_RegHiveUnload)); CodeInfo_RegHiveUnload info = cmd.Info as CodeInfo_RegHiveUnload; string keyPath = StringEscaper.Preprocess(s, info.KeyPath); if (!privilegesEnabled) { RegistryHelper.GetAdminPrivileges(); privilegesEnabled = true; } int result = RegistryHelper.RegUnLoadKey(Registry.LocalMachine.Handle, keyPath); if (result == (int)BetterWin32Errors.Win32Error.ERROR_SUCCESS) { logs.Add(new LogInfo(LogState.Success, $"[HKLM\\{keyPath}] Unloaded")); } else { logs.Add(new LogInfo(LogState.Success, $"Could not unload [HKLM\\{keyPath}], error code = [{result}]")); } return(logs); }