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 162093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:19:47+00:00 2026-05-11T11:19:47+00:00

I am trying to write a utility that will allow moving files in Windows,

  • 0

I am trying to write a utility that will allow moving files in Windows, and when it finds a file in use, will set that file to be moved on reboot.

It seems that MoveFileEx (http://msdn.microsoft.com/en-us/library/aa365240(VS.85).aspx) is the right call for this, however I cannot figure out what error code I’m looking for from GetLastError (http://msdn.microsoft.com/en-us/library/ms679360(VS.85).aspx) to see that the file was in use.

I want the utility to fail when there is an actual permissions problem. Is there anyway to differentiate a you-can’t-write-there and a in-use overwrite error?

Also, if I have the files I am moving in the user’s temporary folder, will they get deleted before the delayed rename?

  • 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. 2026-05-11T11:19:47+00:00Added an answer on May 11, 2026 at 11:19 am

    You have to call CreateFile first to see if the file is in use.

    To see if the file is in use:

    If you get a valid file handle then you know the file does not have conflicting sharing permissions with a process that already has this file open.

    If you specify no sharing access (0 to the dwShareMode parameter of the CreateFile call), then you will not get a file handle if any other process is currently using that file in any way. GetLastError in this case would return: ERROR_SHARING_VIOLATION (32)


    To see if there is a security problem with accessing the file:

    To see if there is a permissions problem accessing that file, the CreateFile call will also fail but with a different GetLastError. You will get: ERROR_ACCESS_DENIED (5)

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

Sidebar

Related Questions

Trying to write a PowerShell cmdlet that will mute the sound at start, unless
I'm trying to write a regex function that will identify and replace a single
I'm trying to write a small utility that maps stdin/stdout to a serial port
I am trying to write a client utility that to connect to Tomcat via
i trying to write a comment in each PHP file, then the comment will
I'm trying to write a script that can control different windows from different programs
I'm trying to write a simple game/utility to calculate poker odds. I know there's
I'm trying to write a custom WPF ValidationRule to enforce that a certain property
I'm trying to write some PHP to upload a file to a folder on
I'm trying to write a stored procedure to select employees who have birthdays that

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.