Solved

Overwrite file-in-use

Posted on 1998-11-19
16
400 Views
Last Modified: 2010-08-05
I have a program "Dailer" that calls in to a server, synchronizes a database and downloads updates of programs. But I would like it to be able to update the program "Dialer". If I try to overwrite the exe when the program is running I will get an error. (I don(t want the user to run another program)
0
Comment
Question by:FrancisIde
  • 7
  • 5
  • 2
  • +2
16 Comments
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
You can't override a file that is in use.
Windows has feature to override a file at boot time (when it is never in use). This feature is used by setup applications.

Is that what you want?
0
 
LVL 14

Expert Comment

by:waty
Comment Utility
As the application still run, you can not erase the exe file.
0
 
LVL 14

Expert Comment

by:waty
Comment Utility
Hi Mirkwood, you are right, Setup installation allows those kind of work, but for my part, I don't know how to do that.

FrancisIde, reject my answer.
0
 

Author Comment

by:FrancisIde
Comment Utility
Hi Mirkwood ,
How should I use this feature.
 

0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
What are you using Win95/winnt or both?

0
 

Author Comment

by:FrancisIde
Comment Utility
Hi Mirkwood ,
How should I use this feature.
 

0
 

Author Comment

by:FrancisIde
Comment Utility
It's used on W95. But if you know how to do it for NT, I would be interested in that too
0
 

Author Comment

by:FrancisIde
Comment Utility
It's used on W95. But if you know how to do it for NT, I would be interested in that too
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 2

Expert Comment

by:mtoft
Comment Utility
I have seen a few of these "Program Update" utilities, that also can update themselves. Usually they solve the problem with "updating" themselves by having 2 "Program Update" exe's!

Ie, when Dailer1 detects that there is a new version of itself, it starts Dailer2 and shuts itself down - Dailer2 does the downloading, copies the new Dialer into Dailer1's place and starts it...

Dailer2 could be a simple version of Dailer1 with no database syncro facilities.

Hope it helps
/Mtoft
0
 

Author Comment

by:FrancisIde
Comment Utility
It's used on W95. But if you know how to do it for NT, I would be interested in that too
0
 

Author Comment

by:FrancisIde
Comment Utility
It's used on W95. But if you know how to do it for NT, I would be interested in that too
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
What are you using Win95/winnt or both?

0
 

Author Comment

by:FrancisIde
Comment Utility
It's used on W95. But if you know how to do it for NT, I would be interested in that too
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 100 total points
Comment Utility
From the MSDN (for win95)

Using a WININIT.INI File to Replace DLLs

Installation programs often need to replace old DLL files with new versions. However, the system does not allow a DLL file to be replaced if the DLL is currently loaded into memory. To solve this problem, your installation program must copy the new DLLs to the user's machine, giving each new DLL a temporary name that is different from that of the corresponding old DLL. Your installation program must also copy a file called WININIT.INI to the user's machine. The WININIT.INI file is processed by the WININIT.EXE program when the system is restarted, before any DLLs are loaded. The WININIT.INI file specifies the destination path and filename for each new DLL.

The WININIT.INI file contains a [rename] section that specifies the source and destination path and filenames for the new DLLs. The entries in the [rename] section have the following syntax:

DestinationFileName=SourceFileName



Use the following syntax to delete a file:

NUL=SourceFileName



The following example shows a [rename] section from a WININIT.INI file:

[rename]
C:\WINDOWS\Fonts\arial.ttf=C:\WINDOWS\Fonts\arial.win
C:\WINDOWS\SYSTEM\advapi32.dll=C:\WINDOWS\SYSTEM\advapi32.tmp



When the system is restarted, it searches for a WININIT.INI file and, if it finds one, runs WININIT.EXE on the file. After processing the file, WININIT.EXE renames it to WININIT.BAK.
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
HOWTO: Moving Files That Are Currently in Use

Last reviewed: April 11, 1997
Article ID: Q140570 The information in this article applies to:

•Microsoft Win32 Application Programming Interface (API) included with: - Microsoft Windows 95 - Microsoft Windows NT versions 3.51, 4.0







SUMMARY

Sometimes Win32 applications need to delete, rename, or move files that are currently being used by the system. One common example is that setup programs need to remove themselves from the user's hard disk when they are finished setting up a software package. Sometimes, they also need to move device drivers that are currently being used by the system. Applications need help from the operating system to delete or move these files.

Windows 95 and Windows NT each provide a unique method for helping applications to remove, replace, or rename files and directories that are in use. Although the two platforms differ in how they implement these methods, both share an overall strategy where the application specifies which files to process, and the system processes them when it reboots. This article explains how applications can use the method provided by each Windows platform.





MORE INFORMATION





Moving Files in Windows NT

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.

To move or replace a file or directory that is in use, an application must specify both a source and destination path on the same volume (for example, drive C:). If the destination path is an existing file, it will be overwritten. If the destination path is an existing directory, it will not be overwritten and both the source and destination paths will remain unchanged. Here is an example call to move or replace a file or move a directory:



   // Move szSrcFile to szDstFile next time system is rebooted
   MoveFileEx(szSrcFile, szDstFile, MOVEFILE_DELAY_UNTIL_REBOOT);




To delete a file or directory, the application must set the destination path to NULL. If the source path is a directory, it will be removed only if it is empty. Note that if you must use MoveFileEx() to remove files from a directory, you must reboot the computer before you can call MoveFileEx() to remove the directory. Here is an example of how to delete a file or empty a directory:



   // Delete szSrcFile next time system is rebooted
   MoveFileEx(szSrcFile, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);






Moving Files in Windows 95

Windows 95 does not implement MoveFileEx(), but does provide an alternate way for all Win32-based, 16-bit Windows-based, and MS-DOS-based applications to move, replace, or delete files (but not directories) that are currently in use. This capability is implemented through the [rename] section of a file named Wininit.ini. If Wininit.ini is present in the Windows directory, Wininit.exe processes it when the system boots. Once Wininit.ini has been processed, Wininit.exe renames it to Wininit.bak.

The syntax of the [rename] section is:



   DestinationFileName=SourceFileName




DestinationFileName and SourceFileName must reside on the same volume and be short (8.3) file names because Wininit.ini is processed before the protected mode disk system is loaded, and long file names are only available when the protected mode disk system is running. Destination and source files specified in Wininit.ini with long file names are ignored.

The [rename] section can have multiple lines with one file per line. To delete a file, specify NUL as the DestinationFileName. Here are some entry examples:



   [rename]
   NUL=C:\TEMP.TXT
   C:\NEW_DIR\EXISTING.TXT=C:\EXISTING.TXT
   C:\NEW_DIR\NEWNAME.TXT=C:\OLDNAME.TXT
   C:\EXISTING.TXT=C:\TEMP\NEWFILE.TXT




The first line causes Temp.txt to be deleted. The second causes Existing.txt to be moved to a new directory. The third causes Oldname.txt to be moved and renamed. The fourth causes an existing file to be overwritten by Newfile.txt.

Applications should not use WritePrivateProfileString() to write entries to the [rename] section because there can be multiple lines with the same DestinationFileName, especially if DestinationFileName is "NUL." Instead, they should add entries by parsing Wininit.ini and appending the entries to the end of the [rename] section.

NOTE: Always use a case-insensitive search to parse Wininit.ini because the title of the [rename] section and the file names inside it may have any combination of uppercase and lowercase letters.

Applications that use Wininit.ini should check for its existence in the Windows directory. If Wininit.ini is present, then another application has written to it since the system was last restarted. Therefore, the application should open it and add entries to the [rename] section. If Wininit.ini isn't present, the application should create it and add to the [rename] section. Doing so ensures that entries from other applications won't be deleted accidentally by your application.

To undo a file rename operation before the system is rebooted, you must remove the corresponding line from the [rename] section of the Wininit.ini file.
0
 
LVL 14

Expert Comment

by:Matti
Comment Utility
Hi!

You can't tamper whit that exe whit out loosing the conection.

You need to install an instalationset for that update during
the conection you may use the application directory and make a subdirectory for that instalation set (be avare of max filename
leght in here)

This set may be normal VB Setup program and set of files.

If you have not taucht this in current version, you may
make it so that this instalation programs starts when uses
NEXT time boots his/her computer.

This is very common way whit network maintance programs today.

To cover this you need make an program icon whit the path information to users Windows startup folder. The program must make uses a question shall this update be done now or not.

For the next version you may make your prog so that if uses
download the update and next time hi/her starts using your prog
it will ask shall we update it or not.

Matti




0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now