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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 169k
  • Answers 169k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You don't need installutil.exe and probably you don't even have… May 12, 2026 at 1:57 pm
  • Editorial Team
    Editorial Team added an answer You must check the SQL Server Service account has modify… May 12, 2026 at 1:57 pm
  • Editorial Team
    Editorial Team added an answer This is a good question; I'm sure it's one that… May 12, 2026 at 1:56 pm

Related Questions

I tried to write a Utility Manager application, and I am trying to test
I have a method with an out parameter that tries to do a type
I'm trying to write a simple GUI application using Qt framework. The purpose of
I am trying to get a dynamically loaded LinkButton to fire a postback event,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.