Jump to content
Tuts 4 You



Recommended Posts

Hi guys,

I haveĀ  a question again.I wanna create a new file via CreateFile + WriteFile which I then wanna execute via CreateProcess API.The problem I have that I dont get it work and always get a Sharing Violation Error on CreateProcess API.I would like to use the flag FILE_FLAG_DELETE_ON_CLOSE so that file gets deleted after handle is closed so that I dont need to handle it by myself anymore.But as I said,CreateProcess API does fail if I dont close the handle from CreateFile before but if I close the handle then the file gets deleted of course.So does anyone know whether there is way to handle it right with using FILE_FLAG_DELETE_ON_CLOSE + CreateProcess after?CreateFile / WriteFile & CreateProcess.

Thank you

Link to comment

what sharing rights have you given it ? FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ?

Edited by evlncrn8
Link to comment


yes I tried the flags too


invoke WriteFile ....

mov startupinfo1.cb,sizeof STARTUPINFO
invoke GetStartupInfo,addr startupinfo1
invoke CreateProcess,chr$("1232323.exe"),0,0,0,NULL,0,0,0,addr startupinfo1,addr pinfo

but dont get it work.So it seems I have to close that handle before using CreateProcess.Hhhm.Do you see whats wrong here?Or canĀ  you post a example of the right using API flags in that case which are also working for you.


Link to comment

have createprocess inherit the handle ? (in the security attributes part).. then launch and exit, then once the launchee process exits it should do the job, might work

Link to comment
Teddy Rogers

Not sure exactly what you are trying to accomplish, are you trying to patch it first? Perhaps instead use...

  hFile = CreateFile_(Filename.s, #GENERIC_READ | #GENERIC_WRITE, 0, #Null, #OPEN_EXISTING, 0, #Null)
    hFileMappingObject = CreateFileMapping_(hFile, #Null, #PAGE_READWRITE, 0, 0, #Null)
    If hFileMappingObject
      *lpBaseAddress = MapViewOfFile_(hFileMappingObject, #FILE_MAP_WRITE, 0, 0, 0)
    	If *lpBaseAddress
      	  ; Do stuff...


Link to comment

Hi guys,

so I did also try to enable inherit etc but also didnt work.Just need any example how it would work from createfile (FILE_FLAG_DELETE_ON_CLOSE) - createprocess.

So I just try to create a new file where I writes bytes into (small new exe) and then I just wanna start it and if its not used anymore then system should delete it.Thats all so far.Of course I could do it without using FILE_FLAG_DELETE_ON_CLOSE and delete file by myself but if there is already a option / flag like this then I would also try to use / test it out you know.Just wanted to get it work with using that flag.


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...