使用 Inno Setup 以二进制格式将当前日期存储到注册表

Storing the current date to the registry in binary format with Inno Setup

是否可以使用 Inno Setup 将当前日期作为 二进制数据 写入注册表项? (如果它是一个字符串,那么其他人就很容易更改)

在我的 MFC C++ 项目中,我序列化了一个 DATE variable using WriteProfileBinary

最终我需要能够使用 .NET C# 将此值读入 DateTime 变量。我将使用通用程序数据键来存储值,并且仅当不存在时才使用。


[Registry] 适合二进制数据:

If binary is specified, Setup will create a binary (REG_BINARY) value ... If the data type is binary, this is a sequence of hexadecimal bytes in the form: "00 ff 12 34".

我们如何获取 时间戳 并将其转换为所需的格式?


我看到这个问题 (),这个问题很有用,在 Inno Setup 论坛上他们也回复了我:

It's possible, but you'll have to use some [Code] and the RegWriteBinaryValue function.

但我还是不太清楚:

  1. 如何使用此函数将当前时间戳写入注册表?
  2. 如何以二进制格式编写它,以便 .NET C# 能够将其作为 DateTime 对象读取?

要将当前日期作为二进制值写入注册表,您可以这样做:

var
  DateStr: string;
begin
  DateStr := GetDateTimeString('yyyy/mm/dd', '-', ':');
  RegWriteBinaryValue(
    HKEY_AUTO, 'Software\My Company\My Program', 'InstallDate', DateStr);
end;

它将导致:

C:\>reg query "HKCU\Software\My Company\My Program"

HKEY_CURRENT_USER\Software\My Company\My Program
    InstallDate    REG_BINARY    323032312D31302D3039  

如果你愿意,你可以做更多的混淆。无论您做什么,用户都可以或多或少地修改该值。