Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6904063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:00:12+00:00 2026-05-27T08:00:12+00:00

The Windows API function CreateFile function allows you to specific the desired access. There

  • 0

The Windows API function CreateFile function allows you to specific the desired access. There are three options read, write and delete. If you get a handle from CreateFile requesting Delete access how do you then delete the file using the returned handle? The DeleteFile function takes the file name, not the handle.

Big Picture:
When saving files from my application I write out to a temporary file first, then delete the “real” file and rename the temporary file to the real name. I have started to see problems with search indexers, or anti virus/spyware opening the file for reading but not allowing deletes. This causes my save to fail when moving the files around. I have changed my open code to request delete access to make sure I can delete the file when it comes time to save.

This all works fine but I still have a gap where a third party application could grab my file. Since I have an open handle to both the temporary and real files I was looking for a way to perform the delete and rename functions using those handles. The only option I can find is to close the handles and then call the DeleteFile and MoveFile functions. Actually I am currently using the ReplaceFile API function to perform those steps, but it too has file names passed in and will not work unless I close my handles first.

I still need to support XP and cannot start using the new transaction file functions. Is there any way to keep the files locked and still delete/rename them?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:00:13+00:00Added an answer on May 27, 2026 at 8:00 am

    In Windows Vista there is that function SetFileInformationByHandle, that can do what you need.

    In previous versions of Windows there is no such function, but you have the equivalent native, not quite public function NtSetInformationFile.

    I have no experience with these functions, nor a Windows machine to test them, so I cannot show you the code, but that should not be so difficult.

    The general disclaimer about native Windows functions apply, of course.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there in Windows API or in MFC any analog to atoh() function? atoh()
Are there Windows API functions that allows reading what the current password policy is?
The Windows API function CopyFile has an argument BOOL bFailIfExists that allows you to
The Windows API function CryptBinaryToString isn't supported on Windows 2000. Is there and alternative?
In C++, if you try to get a function pointer of a Windows API
Windows API function GetRawInputDeviceInfo has a parameter uiCommand . One of the options is
Is there a Windows API function to extract the drive letter from a Windows
Hello is there any windows API function that would return if drive is writable.
On my Windows 7 system, the GetVersionEx Windows API function returns 6.0, indicating Windows
Windows API ::FindWindow function fails when called from Service application. GetLastError() also returns 0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.