AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Code-Bibliothek Library: Dateien / Laufwerke Delphi Dateiendungen registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Dateiendungen registrieren

Ein Thema von Meflin · begonnen am 12. Jun 2004 · letzter Beitrag vom 21. Nov 2004
Antwort Antwort
CalganX

Registriert seit: 21. Jul 2002
Ort: Bonn
5.403 Beiträge
 
Turbo Delphi für Win32
 
#1

Re: Dateiendungen registrieren

  Alt 21. Nov 2004, 22:29
Und für den Fall, dass der ausführende User keine Adminrechte hat, hat der ehemalige User notErnie folgenden Source zusammengestellt, der allerdings von MathiasSimmack's Klasse (vorherige Beitragsanhang) unabhängig ist.
Delphi-Quellcode:
//----von Mathias Simmacks "IsAdmin.inc" (TFileTypeRegistration.zip) geklaut:

function GetAdminSid: PSID;
const
  // bekannte SIDs ... (WinNT.h)
  SECURITYNTAUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));
  // bekannte RIDs ... (WinNT.h)
  SECURITYBUILTINDOMAINRID: DWORD = $00000020;
  DOMAINALIASRIDADMINS: DWORD = $00000220;
begin
  Result := nil;
  AllocateAndInitializeSid(SECURITYNTAUTHORITY,
    2,
    SECURITYBUILTINDOMAINRID,
    DOMAINALIASRIDADMINS,
    0,
    0,
    0,
    0,
    0,
    0,
    Result);
end;

//----von Mathias Simmacks "IsAdmin.inc" (TFileTypeRegistration.zip) geklaut:

function IsAdmin: LongBool;
var
  TokenHandle: THandle;
  ReturnLength: DWORD;
  TokenInformation: PTokenGroups;
  AdminSid: PSID;
  Loop: Integer;
  wv: TOSVersionInfo;
begin
  wv.dwOSVersionInfoSize := sizeof(TOSversionInfo);
  GetVersionEx(wv);

  Result := (wv.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS);

  if (wv.dwPlatformId = VER_PLATFORM_WIN32_NT) then
  begin
    TokenHandle := 0;
    if OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, TokenHandle) then
    try
      ReturnLength := 0;
      GetTokenInformation(TokenHandle, TokenGroups, nil, 0, ReturnLength);
      TokenInformation := GetMemory(ReturnLength);
      if Assigned(TokenInformation) then
      try
        if GetTokenInformation(TokenHandle, TokenGroups,
          TokenInformation, ReturnLength, ReturnLength) then
        begin
          AdminSid := GetAdminSid;
          for Loop := 0 to TokenInformation^.GroupCount - 1 do
          begin
            if EqualSid(TokenInformation^.Groups[Loop].Sid, AdminSid) then
            begin
              Result := True; break;
            end;
          end;
          FreeSid(AdminSid);
        end;
      finally
        FreeMemory(TokenInformation);
      end;
    finally
      CloseHandle(TokenHandle);
    end;
  end;
end;

//------------------------

//////////////////////////

function WVersion: string;
var
  OSInfo: TOSVersionInfo;
begin
  Result := '3X';
  OSInfo.dwOSVersionInfoSize := sizeof(TOSVERSIONINFO);
  GetVersionEx(OSInfo);
  case OSInfo.dwPlatformID of
    VER_PLATFORM_WIN32S: begin
        Result := '3X';
        Exit;
      end;
    VER_PLATFORM_WIN32_WINDOWS: begin
        Result := '9X';
        Exit;
      end;
    VER_PLATFORM_WIN32_NT: begin
        Result := 'NT';
        Exit;
      end;
  end; //case
end;

procedure registerfiletype(Handle: HWnd; ft, key, desc, icon, prg: string);
// Benutzung z.b. für ZIP-Dateien:
// registerfiletype(Handle, '.zip', '', 'Zip-Archiv', paramstr(0) + ',1', paramstr(0));
var
  myReg: TRegIniFile;
  wo: byte;
begin

  if WVersion = '3Xthen
  begin
  //MessageBox(Handle, 'Window 3.x wird nicht unterstützt.', 'Information', mb_IconInformation);
    exit;
  end;

  wo := pos('.', ft);

  while wo > 0 do begin
    delete(ft, wo, 1);
    wo := pos('.', ft);
  end;

  if (ft = '') or (prg = '') then exit;
  if pos('*', ft) <> 0 then exit;
  if pos('?', ft) <> 0 then exit;

  ft := '.' + ft;

  try
    myReg := TRegIniFile.create('');

    if (WVersion = '9X') or (IsAdmin = true) then
    begin
      //MessageBox(Handle, 'Admin-Rechte oder Win9x.', 'Information', mb_IconInformation);
      myReg.RootKey := HKEY_CLASSES_ROOT;
      key := ExtractFileName(Application.ExeName) + copy(ft, 2, maxint);
    end else
    begin
      myReg.RootKey := HKEY_CURRENT_USER;
      key := '\Software\Classes\.' + copy(ft, 2, maxint);
    end;

    myReg.WriteString(ft, '', key);
    myReg.WriteString(key, '', desc);

    if icon <> 'then
      myReg.WriteString(key + '\DefaultIcon', '', icon);

    myReg.WriteString(key + '\shell\open\command', '', '"' + prg + '" "%1"');

  finally
    myReg.free;
  end;

  SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
  MessageBox(Handle, PChar('Der Dateityp "*' + ft + '" wurde mit ' + ExtractFileName(Application.ExeName) + ' verknüpft.'), 'Information', mb_IconInformation);
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 09:04 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 by Thomas Breitkreuz