Article

From:
To:
All
Subject:
On demand elevation in Delphi applicatio to create folder in 'ProgramFiles' folder [Edit]
Newsgroup:
embarcadero.public.delphi.com.activex.using

On demand elevation in Delphi applicatio to create folder in 'ProgramFiles' folder [Edit]

Hello all,

I'd like the have a on demand elevation of an filesystem COM object, so I can delete/rename/create items in the 'Program Fiels' folder.
So far I found some code about running a 'out of process' COM object with evevated rights (see code below)
But now I need some 'objects' ClassID / Interface ID etc to actually do some fiel system actions....
--------------------------------------------------------------------------- type   PBindOpts3 = ^TBindOpts3; {$EXTERNALSYM tagBIND_OPTS3}   tagBIND_OPTS3 = record     cbStruct: DWORD;     grfFlags: DWORD;     grfMode: DWORD;     dwTickCountDeadline: DWORD;     dwTrackFlags: DWORD;     dwClassContext: DWORD;     locale: LCID;     pServerInfo: Pointer;     hwnd: hwnd;   end;   TBindOpts3 = tagBIND_OPTS3; {$EXTERNALSYM BIND_OPTS3}   BIND_OPTS3 = TBindOpts3;
function CoGetObject(pszName: PWideChar; pBindOptions: PBindOpts3;       const iid: TIID; ppv: PPointer): HResult; stdcall; external 'ole32.dll';
procedure CoCreateInstanceAsAdmin(const Handle: HWND;       const ClassID, IID: TGuid; PInterface: PPointer); var    BindOpts: TBindOpts3;    MonikerName: WideString;    Res: HRESULT; begin    ZeroMemory(@BindOpts, Sizeof(TBindOpts3));    BindOpts.cbStruct := Sizeof(TBindOpts3);    BindOpts.hwnd := Handle;    BindOpts.dwClassContext := CLSCTX_LOCAL_SERVER;
   MonikerName := 'Elevation:Administrator!new:' + GUIDToString(ClassID);
   Res := CoGetObject(PWideChar(MonikerName), @BindOpts, IID, PInterface);    if Failed(Res) then       raise Exception.Create(SysErrorMessage(Res)); end; ---------------------------------------------------------------------------
-- Regards,
Ronald Hoek
Application Developer ComponentAgro B.V. Oud-Beijerland - The Netherlands
http://www.componentagro.nl
KvK: H24264020
Edited by: Ronald Hoek on Apr 11, 2013 1:17 AM
FYI: Phrase searches are enclosed in either single or double quotes
 
 
Originally created by
Tamarack Associates
Tue, 19 Nov 2024 14:52:02 UTC
Copyright © 2009-2024
HREF Tools Corp.