gpt4 book ai didi

inno-setup - 确定运行提升的 Inno Setup 安装程序的管理员帐户是否与当前 Windows 登录 session 的帐户相同

转载 作者:行者123 更新时间:2023-12-05 04:08:05 25 4
gpt4 key购买 nike

我在我的 Inno Setup 脚本中使用 PrivilegesRequired=lowest。如果安装程序以提升的方式运行,即 IsAdminLoggedOn 或 IsPowerUserLoggedOn 报告 TRUE,我如何确定提升的用户帐户是否与启动安装程序的帐户相同?

我的脚本可以相应地做不同的事情。

最佳答案

您可以使用 WTSQuerySessionInformation检索当前 Windows 登录 session 的帐户用户名。

function WTSQuerySessionInformation(
hServer: THandle; SessionId: Cardinal; WTSInfoClass: Integer;
var pBuffer: DWord; var BytesReturned: DWord): Boolean;
external 'WTSQuerySessionInformationW@wtsapi32.dll stdcall';

procedure WTSFreeMemory(pMemory: DWord);
external 'WTSFreeMemory@wtsapi32.dll stdcall';

procedure RtlMoveMemoryAsString(Dest: string; Source: DWord; Len: Integer);
external 'RtlMoveMemory@kernel32.dll stdcall';

const
WTS_CURRENT_SERVER_HANDLE = 0;
WTS_CURRENT_SESSION = -1;
WTSUserName = 5;

function GetCurrentSessionUserName: string;
var
Buffer: DWord;
BytesReturned: DWord;
QueryResult: Boolean;
begin
QueryResult :=
WTSQuerySessionInformation(
WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSUserName, Buffer,
BytesReturned);

if not QueryResult then
begin
Log('Failed to retrieve username');
Result := '';
end
else
begin
SetLength(Result, (BytesReturned div 2) - 1);
RtlMoveMemoryAsString(Result, Buffer, BytesReturned);
WTSFreeMemory(Buffer);
Log(Format('Retrieved username "%s"', [Result]));
end;
end;

(代码适用于 Unicode version of Inno Setup – Inno Setup 6 的唯一版本)。


然后您可以将结果与 GetUserNameString 进行比较.


您可能需要在比较中添加域名。

关于inno-setup - 确定运行提升的 Inno Setup 安装程序的管理员帐户是否与当前 Windows 登录 session 的帐户相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48069354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com