Reputation: 19924
I want to write to registry based on OS. I have OS detection function in place and found out that you can put a check function in registry section, so tried following:
Root: HKLM; SubKey: Software\Microsoft\Windows; ValueType: dword; ValueName: Test; ValueData: 1; Flags: createvalueifdoesntexist; Check: IsWindows7
But it didn't work, means that when I installed on Win7 and WinXP, it wrote the value to the registry in both cases.
Here is the code to detect OS:
function IsWindows7(): Boolean;
var
Version: TWindowsVersion;
begin
GetWindowsVersionEx(Version);
// Windows 7 version is 6.1 (workstation)
if (Version.Major = 6) and
(Version.Minor = 1) and
(Version.ProductType = VER_NT_WORKSTATION)
then
Result := True
else
Result := False;
end;
Any ideas/suggestions?
Upvotes: 3
Views: 2770
Reputation: 2312
Please see below my solution for you:
[Registry]
Root: HKLM; SubKey: {code:IsWindows7}; ValueType: dword; ValueName: Test; ValueData: 1; Flags: createvalueifdoesntexist; Check: IsWindows7
[Code]
function IsWindows7(S: String) : string;
var
Version: TWindowsVersion;
begin
GetWindowsVersionEx(Version);
// Windows 7 version is 6.1 (workstation)
if (Version.Major = 6) and
(Version.Minor = 1) and
(Version.ProductType = VER_NT_WORKSTATION)
then
Result := '<registry path for win 7>'
else
Result := '<registry path for other win os >';
end;
Happy coding!
Upvotes: 5