1

Topic: Transmission handle a file between processes

I conceived to teach the aaplet to work with files with temporal increase of privileges. Created inproc com the server which is launched through CoGetObject (' Elevation:Administrator! new: {mine GUID} '), with it of problems are not present,  the window with request of privileges appears, launched DllHost.exe with the raised privileges in which I works inproc com the server. In the server I cause CreateFileW, and received handle I want to transfer in the program. Becomes, it like as through DublicateHandle. Function in the server has about the following appearance: function CreateFile (ACallerProcess: THandle; const AFileName: WideString; out AFileHandle: THandle): HResult; stdcall; var Handle: THandle; begin try Handle: = CreateFileW (PWideChar (AFileName), GENERIC_READ or GENERIC_WRITE, 0, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); DuplicateHandle (GetCurrentProcessId, Handle, ACallerProcessID, @AFileHandle, 0, False, DUPLICATE_SAME_ACCESS); {if AFileHandle = 0 then MessageBox (0, PChar (IntToStr (GetLastError)), ' Error ', MB_ICONHAND);} CloseHandle (Handle); Result: = S_OK; except Result: = E_FAIL; end; end; As ACallerProcess I transfer the such: DuplicateHandle (GetCurrentProcess, GetCurrentProcess, GetCurrentProcess, @CallerProcess, 0, False, DUPLICATE_SAME_ACCESS); or CallerProcess: = OpenProcess (PROCESS_ALL_ACCESS, False, GetCurrentProcessId); But in any  by a call in server DuplicateHandle I have error ERROR_INVALID_HANDLE. Where to dig?

2

Re: Transmission handle a file between processes

A> Handle: = CreateFileW (PWideChar (AFileName), GENERIC_READ or GENERIC_WRITE, 0, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); A> DuplicateHandle (GetCurrentProcessId, Handle, ACallerProcessID, @AFileHandle, 0, False, DUPLICATE_SAME_ACCESS); not GetCurrentProcessId (), and GetCurrentProcess () not ACallerProcessID, and  on process where you want to transfer .  such

3

Re: Transmission handle a file between processes

Hello, ononim, you wrote: O> not GetCurrentProcessId (), and GetCurrentProcess () Nezametil, thanks. O> not ACallerProcessID, and  on process where you want to transfer  (ACallerProcessID are corrigendas, should be ACallerProcess) ACallerProcess I transfer from causing process where I want to transfer , I try to receive its two different methods (in the initial message), but I have an error even taking into account correction of the first error.

4

Re: Transmission handle a file between processes

O>> not ACallerProcessID, and  on process where you want to transfer  A> (ACallerProcessID are corrigendas, should be ACallerProcess) ACallerProcess I transfer from causing process where I want to transfer , I try to receive its two different methods (in the initial message), but I have an error even taking into account correction of the first error. Both methods incorrect as both create , belonging to the process. It is logical to make ACallerProcess: = OpenProcess (PROCESS_ALL_ACCESS, False, ACallerProcess ID); in that process which  wants. If it is, of course, possible. And if is not present - it is necessary to understand in details that is possible in your conditions and that is not present.

5

Re: Transmission handle a file between processes

Hello, ononim, you wrote: O> it is logical to make Thanks, helped. Well and after a question. How most easier to span SECURITY_ATTRIBUTES from causing process in mine com the server? Whether there will be correct structure SECURITY_DESCRIPTOR after simple serialization and the subsequent deserialising?

6

Re: Transmission handle a file between processes

A> Thanks, helped. Well and after a question. How most easier to span SECURITY_ATTRIBUTES from causing process in mine com the server? Whether there will be correct structure SECURITY_DESCRIPTOR after simple serialization and the subsequent deserialising? SECURITY_ATTRIBUTES it is two  and the pointer on SECURITY_DESCRIPTOR. Concerning serialization last, there is such here a reading matter: https://msdn.microsoft.com/en-us/librar … p/aa374807 (v=vs.85).aspx

7

Re: Transmission handle a file between processes

Hello, ononim, you wrote: O> such here Thanks reading matter, like all simply would turn out. 1) I check type by means of GetSecurityDescriptorControl and checks of flag SE_SELF_RELATIVE. 2) If the flag is not present, I create a new descriptor by means of MakeSelfRelativeSD. 3) Serializuju.

8

Re: Transmission handle a file between processes

A> 1) I Check type by means of GetSecurityDescriptorControl and checks of flag SE_SELF_RELATIVE. A> 2) If the flag is not present, I create a new descriptor by means of MakeSelfRelativeSD. A> 3) Serializuju. On other side probably it is necessary to overtake backwards in an absolute format. Anyway I faced some f which not  self-relative SD. But it was so a long time...