Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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
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 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
add comment

Your Answer

 
discard

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.