AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Nur als Dienst starten lassen

Ein Thema von TPeterT · begonnen am 16. Nov 2005 · letzter Beitrag vom 16. Nov 2005
Antwort Antwort
NicoDE
(Gast)

n/a Beiträge
 
#1

Re: Nur als Dienst starten lassen

  Alt 16. Nov 2005, 09:53
Unter welchem Account (z.B. SYSTEM) wird der Dienst ausgeführt?

Denn wenn der Dienst unter dem lokalen SYSTEM-Account ausgeführt wird, dann könnte man in den Quelltext der Projektdatei schreiben:
Delphi-Quellcode:
if not IsLocalSystem() then
begin
  MessageBox(0, 'RTFM', nil, MB_ICONERROR or MB_SERVICE_NOTIFICATION);
  Exit;
end;
Die Implementierung von IfLocalSystem() könnte so aussehen:
Delphi-Quellcode:
unit LocalSys;

interface

function IsLocalSystem(): Boolean;

implementation

uses
  Windows;

function IsLocalSystem(): Boolean;
type
  PTokenUser = ^TTokenUser;
  TTokenUser = record
    User: TSidAndAttributes;
  end;
const
  SECURITY_NT_AUTHORITY: TSidIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));
const
  SECURITY_LOCAL_SYSTEM_RID = $00000012;
var
  TokenHandle: THandle;
  TokenInformation: PTokenUser;
  TokenInformationLength: DWORD;
  LocalSystemSid: PSid;
begin
  Result := False;
  if not OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, TokenHandle) then
    Exit;
  try
    TokenInformationLength := 0;
    GetTokenInformation(TokenHandle, TokenUser, nil, 0, TokenInformationLength);
    TokenInformation := GetMemory(TokenInformationLength);
    if nil = TokenInformation then
      Exit;
    try
      if not GetTokenInformation(TokenHandle, TokenUser, TokenInformation,
        TokenInformationLength, TokenInformationLength) then
        Exit;
      if not AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 1,
        SECURITY_LOCAL_SYSTEM_RID, 0, 0, 0, 0, 0, 0, 0, LocalSystemSid) then
        Exit;
      try
        Result := EqualSid(LocalSystemSid, TokenInformation.User.Sid);
      finally
        FreeSid(LocalSystemSid);
      end;
    finally
      FreeMemory(TokenInformation);
    end;
  finally
    CloseHandle(TokenHandle);
  end;
end;

end.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:26 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz