Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to write a script that forces closed a specific file and then copies it from one server to another.

To manually do this I would use

Administrative Tools --> Computer Management --> Shared Folders --> Open Files

Is there a way to script this?

share|improve this question
up vote 5 down vote accepted

I've used the SysInternals utility Handle in the past and wrapped a script around that before.

You could also use the command:

net file /close 
share|improve this answer
This is a good answer, but be careful OP, as force-closing a handle out from underneath the process that was using it can cause that process to crash or behave unpredictably. – Ryan Ries Oct 1 '12 at 18:15
+1 I agree that it can cause instability in the server/application depending on the application and the file you are closing. Generally, applications hold files open for a reason - but, I've had instances where a poorly-written app was misbehaving.. caution is always advised though and I generally wouldn't rely on this for production level solutions. – Rex Oct 1 '12 at 20:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.