The information in this article applies to:
SUMMARY
Sometimes an installation program needs to replace a file that is currently
being used by the operating system. This is often necessary when a driver
is being updated. This article explains how to handle such an update under
Windows CE using the MoveFile API.
MORE INFORMATIONMany Windows CE drivers are listed in the registry under the key
Each built-in driver has a subkey that
contains various values that the operating system uses when loading the
driver. The "Dll" value is a REG_SZ value, which identifies the file that
houses the driver. This file is in use as soon as the operating system is
started.
NOTE: Under Windows NT, a file that is in use should be replaced with the MoveFileEx() API, which allows the file to be replaced upon a system restart. Under Windows 9x, you can use a WINInit.ini file to replace a file upon system restart. For more information on these methods of replacing files, please see the following article in the Microsoft Knowledge Base: Q140570 HOWTO: Move Files That Are Currently in UseUnfortunately, Windows CE does not support the MoveFileEx function or the use of a WINInit.ini file. Furthermore, a call to DeleteFile() fails if the file is in use, and a call to GetLastError() returns error code 5 Under Windows CE, you can use the MoveFile() API to move a file to a different directory, even if the file is in use. The system continues to use the file from its new location so an attempt to delete it after the move still fails. However, once the file has been moved, a replacement file can be stored at the original location. Upon restart of the Windows CE device, the operating system uses the new file and the old file can be successfully deleted. The following sample code demonstrates how to move a file that is in use to the recycle bin. The program first tries to delete the file with the DeleteFile() API. If this fails, it calls the MoveFile() function to move the file. Sample Code
NOTE: When a file that is in use is moved to the Recycle Bin, its name
becomes unreadable. It usually shows up in Windows Explorer as nonsense
characters. If you want to open a file by name after moving it, you should
move it to a temporary directory. Furthermore, any attempt to empty the
Recycle Bin does not successfully remove a file that is in use. Once the
device has been restarted, you can successfully empty the Recycle Bin.
Additional query words:
Keywords : kbAPI kbDLL kbKernBase kbWinCE100 kbWinCE200 kbGrpShell |
Last Reviewed: December 3, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |