Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to use FILE_FLAG_DELETE_ON_CLOSE?

Featured Replies

Posted

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

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

Edited by evlncrn8

  • Author

Hi,

yes I tried the flags too

invoke CreateFile,chr$("1232323.exe"),GENERIC_READ + GENERIC_WRITE,FILE_SHARE_READ + FILE_SHARE_WRITE + FILE_SHARE_DELETE,NULL,CREATE_ALWAYS,FILE_FLAG_DELETE_ON_CLOSE ,NULL

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.

greetz

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

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)
  
  If hFile <> #INVALID_HANDLE_VALUE
    hFileMappingObject = CreateFileMapping_(hFile, #Null, #PAGE_READWRITE, 0, 0, #Null)
    
    If hFileMappingObject
      *lpBaseAddress = MapViewOfFile_(hFileMappingObject, #FILE_MAP_WRITE, 0, 0, 0)
      
    	If *lpBaseAddress
    
      	  ; Do stuff...
        
          UnmapViewOfFile_(*lpBaseAddress)
      	EndIf
      
      CloseHandle_(hFileMappingObject)
    EndIf
    CloseHandle_(hFile)
  EndIf

Ted.

  • Author

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.

greetz

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.