3

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?

Simon Foster
  • 2,622
  • 6
  • 38
  • 55

1 Answers1

5

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 
Rex
  • 7,895
  • 3
  • 29
  • 45
  • 1
    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 01 '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 01 '12 at 20:16