How to read registry HKCU for logged In user from Inno Setup installer running as administrator -
my setup set run lowest privileges
privilegesrequired=lowest
but i'm executing setup admin (right click-> run admin, enter admin credential in uac), , want check logged in user's registry in initializesetup()
function initializesetup(): boolean; begin if regquerystringvalue(hkcu,'software\{some path}','version', {some value}) begin { here } end end
but checks registry value admin account, not logged in user account
is there way check logged in users registry @ point?
first, should not try access user environment installer running administrator privileges. that's wrong.
for general discussion on topic, see:
installing application logged in user inno setup installer running administrator.
anyway, can use function below.
the code combines these solutions:
- inno setup creating registry key logged in user (not admin user)
- inno setup installs admin's appdata directory
function reqqueryvalueoforiginaluser(var resultstr: string): boolean; var uniq: string; tempfilename: string; cmd: string; key: string; value: string; params: string; lines: tarrayofstring; buf: string; resultcode: integer; p: integer; begin log('querying registry value of original user'); uniq := extractfilename(expandconstant('{tmp}')); tempfilename := expandconstant(format('{commondocs}\appdata-%s.txt', [uniq])); cmd := expandconstant('{cmd}'); key := 'hkey_current_user\software\{some path}'; value := 'version'; params := format('/c reg.exe query "%s" /v "%s" > "%s"', [key, value, tempfilename]); result := false; if execasoriginaluser(cmd, params, '', sw_hide, ewwaituntilterminated, resultcode) , (resultcode = 0) begin if loadstringsfromfile(tempfilename, lines) begin if (length(lines[0]) > 0) or (lines[1] <> key) begin log(format('unexpected output of reg.exe query: "%s" - "%s"', [ lines[0], lines[1]])); end else begin buf := trim(lines[2]); if copy(buf, 1, length(value)) <> value begin log(format('unexpected output of value query: "%s"', [buf])); end else begin buf := trim(copy(buf, length(value) + 1, length(buf) - length(value))); p := pos(' ', buf); if p = 0 begin log(format('cannot find type , value separator in "%s"', [buf])); end else begin resultstr := trim(copy(buf, p + 1, length(buf) - p)); log(format('value "%s"', [resultstr])); result := true; end; end; end; end else begin log(format('error reading %s', [tempfilename])); end; deletefile(tempfilename); end else begin log('error querying registry key of original user'); end; result := true; end;
Comments
Post a Comment