1
0
mirror of synced 2024-11-12 22:39:17 +00:00
x2utils/X2UtService.pas

63 lines
1.1 KiB
ObjectPascal
Raw Normal View History

2016-10-21 11:58:28 +00:00
unit X2UtService;
interface
uses
X2UtService.Intf;
type
TX2Service = class(TObject)
public
class function Run(AService: IX2Service): IX2ServiceContext;
end;
function IsUserInteractive: Boolean;
implementation
uses
System.SysUtils,
Winapi.Windows,
X2UtService.GUIContext,
X2UtService.ServiceContext;
function IsUserInteractive: Boolean;
var
windowStation: HWINSTA;
userObject: TUserObjectFlags;
lengthNeeded: Cardinal;
begin
Result := True;
windowStation := GetProcessWindowStation;
if windowStation <> 0 then
begin
lengthNeeded := 0;
FillChar(userObject, SizeOf(userObject), 0);
if GetUserObjectInformation(windowStation, UOI_FLAGS, @userObject, SizeOf(userObject), lengthNeeded) and
((userObject.dwFlags and WSF_VISIBLE) = 0) then
begin
Result := False;
end;
end;
end;
{ TX2Service }
class function TX2Service.Run(AService: IX2Service): IX2ServiceContext;
begin
if TX2ServiceContextService.IsInstallUninstall or (not IsUserInteractive) then
Result := TX2ServiceContextService.Create(AService)
else
2016-10-21 11:58:28 +00:00
Result := TX2ServiceContextGUI.Create(AService);
end;
end.