AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Replace Active File

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
JeremysDad



Joined: 28 Oct 2005
Posts: 102

PostPosted: Fri May 05, 2006 7:40 pm    Post subject: Replace Active File Reply with quote

Hey guys,

I have created a series of scripts about 30 people in our office and have just run into a problem my amateur programmers brain didn't prepare for Embarassed

The scripts are all loaded in a shared drive with the AHK executable. In the morning, the users activate the main script via an icon on their quick launch bar and then access the scripts through a menu activated by the mouse wheel.

I want to upgrade to the latest version of AHK but of course when I try to do so, I get an error from Win2K that the file is in use.

Short of running around the office and trying to get everyone to log out for a few minutes, is there another approach?

I've searched the forums using "Delete + Open" with no success. Any help would be appreciated.

Gary
Back to top
View user's profile Send private message
Atomhrt



Joined: 02 Sep 2004
Posts: 128
Location: Sunnyvale

PostPosted: Fri May 05, 2006 8:53 pm    Post subject: Reply with quote

One way to do it is to use the API MoveFileEX call.

Win32-based applications running on Windows NT should use MoveFileEx() with the MOVEFILE_DELAY_UNTIL_REBOOT flag to move, replace, or delete files and directories currently being used. The next time the system is rebooted, the Windows NT bootup program will move, replace, or delete the specified files and directories.

http://support.microsoft.com/default.aspx?scid=kb;en-us;140570
_________________
I am he of whom he speaks!


Last edited by Atomhrt on Fri May 05, 2006 11:50 pm; edited 1 time in total
Back to top
View user's profile Send private message
Micha



Joined: 15 Nov 2005
Posts: 436
Location: Germany

PostPosted: Fri May 05, 2006 9:19 pm    Post subject: Reply with quote

Hi, I've posted that related at another thread:
Quote:
Hi,
I have the same problem.
On our network I'm not able to delete/replace files which are locked / in use by another person, but I'm able to rename them. Funny, but true.

I had to replace more folders at once. Therefore I rename the folders to the current date "2delete_12042006" and copy the new folder (with the old name) to the network. After a while (with the next update/next day) I'm able to kill the temporary folder, because everybody is using the new/current folder.

Ciao
Micha


You can try it: Try to rename the whole folder while other people have the files locked. If it works, you have a simple solution Smile

Ciao
Micha
Back to top
View user's profile Send private message
Lufia



Joined: 20 Sep 2005
Posts: 16

PostPosted: Sat May 06, 2006 1:21 am    Post subject: Re: Replace Active File Reply with quote

JeremysDad wrote:
Hey guys,

I have created a series of scripts about 30 people in our office and have just run into a problem my amateur programmers brain didn't prepare for Embarassed

The scripts are all loaded in a shared drive with the AHK executable. In the morning, the users activate the main script via an icon on their quick launch bar and then access the scripts through a menu activated by the mouse wheel.

I want to upgrade to the latest version of AHK but of course when I try to do so, I get an error from Win2K that the file is in use.

Short of running around the office and trying to get everyone to log out for a few minutes, is there another approach?

I've searched the forums using "Delete + Open" with no success. Any help would be appreciated.

Gary


I do something similar to this at work. A good idea that I use in my scripts that are run globally is putting a simple line in the script near the beginning like
Code:

IfExist, Exit.txt
{
   ExitApp
}

This way you can just create an empty Exit.txt file out there and it will close on all the PCs giving you enough time to update the executable and delete Exit.txt. Edit: You can also put a msgbox command or something in here saying that the program is being updated and to try again in a few minutes.

If you have administrative rights to the network then you should be able to use a command line tool such as psexec or pskill (pskill needs to be loaded in the users system32 folder I believe for Windows which you could copy there with a script that users run or using login script). With pskill you can close processes out on remote PCs. Also if you have access to the server, you can close out open files by right clicking My Computer, clicking Manage, Shared Folders, Open Files and close out all of the users from the file that way. Smile

Hopefully one of these works for you. Very Happy
_________________
-Lufia
Back to top
View user's profile Send private message
BoBo
Guest





PostPosted: Sat May 06, 2006 7:23 am    Post subject: Reply with quote

Quote:
Short of running around the office and trying to get everyone to log out for a few minutes, is there another approach?
Do your updates at nighttime (WOL), lunchtime (user driven), at their login (via loginscript) and don't miss to log which boxes have been updated successfully! You can use [sysinternals] BGInfo to do pre/post inventory scans.
Back to top
JeremysDad



Joined: 28 Oct 2005
Posts: 102

PostPosted: Sun May 07, 2006 1:23 am    Post subject: Reply with quote

Lufia,
Quote:
I do something similar to this at work. A good idea that I use in my scripts that are run globally is putting a simple line in the script near the beginning like

I absolutely love it!! Very Happy What a great and simple idea...

I'll give that a shot. Thanks for the idea.

Gary
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2393

PostPosted: Sun May 07, 2006 4:56 am    Post subject: Re: Replace Active File Reply with quote

JeremysDad wrote:
The scripts are all loaded in a shared drive with the AHK executable. In the morning, the users activate the main script via an icon on their quick launch bar and then access the scripts through a menu activated by the mouse wheel.


I would suggest not doing things that way. Instead of sharing one AHK executable you could leave the executable in place on the shared drive but have the users copy the file to another directory during login (using a small batch file or script(compiled) in their startup folder or in the registry: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run or HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run or another method if you prefer...) and have them launch their scripts using the copy of the AHK executable instead. This way they will get the latest version each time they login and you will be able to update the main executable on the share since it will not be in use.

One issue that you may eventually run into with the method that you're attempting is that a script may be forced to terminate on a user's machine while in use and cause data loss and/or undesireable results. If the .exe gets updated during login then the scripts that are running can continue to run.
Back to top
View user's profile Send private message Visit poster's website
JeremysDad



Joined: 28 Oct 2005
Posts: 102

PostPosted: Tue May 09, 2006 4:47 pm    Post subject: Reply with quote

Corrupt,
Quote:
Instead of sharing one AHK executable you could leave the executable in place on the shared drive but have the users copy the file to another directory during login (using a small batch file or script(compiled) in their startup folder or in the registry:

Ahh, the subtleties become apparent Smile

So I've started to work on your idea. The only thing I'm not sure of is how to get AHK to recognize the script I wrote. As written right now, it tries to create a default script rather than using mine.

Code:
IfNotExist, h:\CopyDir\
   FileCreateDir, h:\CopyDir

FileCopy, S:\Tools\AutoHotKey.exe, h:\CopyDir\, 1
FileCopy, S:\Tools\AutoHotKey.ini, h:\CopyDir\, 1
Run, h:\NotesToolSDMT\AutoHotKey.exe, MyScript.ahk


Any ideas?

Thanks

Gary
Back to top
View user's profile Send private message
JeremysDad



Joined: 28 Oct 2005
Posts: 102

PostPosted: Tue May 09, 2006 5:24 pm    Post subject: Reply with quote

Quote:
So I've started to work on your idea. The only thing I'm not sure of is how to get AHK to recognize the script I wrote. As written right now, it tries to create a default script rather than using mine.

AHA! Idea I found the SetWorkingDir command and that did the trick. I'll keep playing with this and see how close I can get to Corrupt's suggestion.

Thanks All!

Gary
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group