On 11.04.2013 г. 11:17 ч., Ronald Hoek wrote:
> 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; > --------------------------------------------------------------------------- >
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775771(v=vs.85).aspx
Regards.