Newsgroup: it.comp.lang.visual-basic
Titolo: [?] URGENTE: MoveFileEx API

Sto utilizzando la funzione API "MoveFileEx"
X = MoveFileEx("C:\Windows\System\Msnet32.dll", "C:\Temp\Msnet32.old", 0)
ma non fa nulla............L'ultimo parametro che fa???E' dovuto al fatto
che è in uso???
L'altra funzione CopyFile invece funziona bene....!
Grazie!

che č in uso???
---YES! (mi spieghi come fai a fregare l'auto al tuo amico se quest'ultimo
la sta usando???)


L'alternativa é quella di usare il parametro
MOVEFILE_DELAY_UNTIL_REBOOT(&H4) come ultimo parametro ,questo fa si che i
files vengano spostati al prossimo riavvio di Windows.
Attenzione che MoveFileEx non esiste in Win95/98.
Altre info sul parametro finale...
dwFlags
Set of bit flags that specify how to move the file. You can specify any
combination of the following values. Value Meaning
MOVEFILE_COPY_
ALLOWED If the file is to be moved to a different volume, the function
simulates the move by using the CopyFile and DeleteFile functions.
This flag cannot be used with the MOVEFILE_DELAY_UNTIL_REBOOT flag.
MOVEFILE_DELAY_
UNTIL_REBOOT The function does not move the file until the operating system
is restarted. The system moves the file immediately after AUTOCHK is
executed, but before creating any paging files. Consequently, this parameter
enables the function to delete paging files from previous startups.
This flag can be used only if the process is in the context of a user who
belongs to the administrator group or the LocalSystem account.
This flag cannot be used with the MOVEFILE_COPY_ALLOWED flag.
MOVEFILE_REPLACE_
EXISTING If a file of the name specified by lpNewFileName already exists,
the function replaces its contents with those specified by
lpExistingFileName.
MOVEFILE_WRITE_
THROUGH The function does not return until the file has actually been moved
on the disk.
Setting this flag guarantees that a move performed as a copy and delete
operation is flushed to disk before the function returns. The flush occurs
at the end of the copy operation.
This flag has no effect if the MOVEFILE_DELAY_UNTIL_REBOOT flag is set.
Ciao,
Corrado


In Win95/98 esiste la funzione MoveFileEx, quello che non esiste e' il
parametro MOVEFILE_DELAY_UNTIL_REBOOT.
--
Roal Zanazzi
z...@iol.it

Cito da MSDN:
Windows 95/98: The MoveFileEx function is not supported. To rename or delete
a file at reboot, use the following procedure.
To rename or delete a file on Windows 95/98
Check for the existence of the WININIT.INI file in the Windows directory.
If WININIT.INI exists, open it and add new entries to the existing [rename]
section. If the file does not exist, create the file and create a [rename]
section.
Add lines of the following format to the [rename] section:
DestinationFileName=SourceFileName
Both DestinationFileName and SourceFileName must be short file names. To
delete a file, use NUL as the value for DestinationFileName.
The system processes WININIT.INI during system boot. After WININIT.INI has
been processed, the system names it WININIT.BAK.
Requirements
  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Unsupported.
  Windows CE: Unsupported.
  Header: Declared in winbase.h.
  Import Library: Use kernel32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.
Ciao,
Corrado

 wrote in message
7ql4sv$5pt$1...@fe2.cs.interbusiness.it...


*Posto l'intero articolo tratto da MSDN cosí forse é piú chiaro...*
Ciao,
Corrado
'---------------------------------------------------------------------------
--------------------------------------------
HOWTO: Move Files That Are Currently in Use
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.
Additional query words: update install setup
Keywords          : kbprg kbAPI kbKernBase kbGrpKernBase
Version           : 3.51 4.0
Platform          : NT WINDOWS
Issue type        : kbhowto
'---------------------------------------------------------------------------
--------------------------------------------


<megasnip>
Credo che ci sia un'incoerenza di fondo, dunque, l'help delle API , alla
voce MoveFileEx, QuickInfo (dove sono riportate le informazioni relative
alle varie piattaforme) dice (riporto testualmente):
MoveFileEx
Windows NT    Yes
Windows 95    Yes
Win32s    No
Import Library    kernel32.lib
Header File    winbase.h
Unicode    WinNT
Platform Notes    Windows 95: MOVEFILE_DELAY_UNTIL_REBOOT not supported.
Oltretutto, nei parametri e' scritto:
MOVEFILE_DELAY_UNTIL_REBOOT
_Windows NT only_: The function does not move the file until the operating
system is restarted. The system moves the file immediately after AUTOCHK is
executed, but before creating any paging files. Consequently, this parameter
enables the function to delete paging files from previous startups.
La dicitura "Windows NT only" non avrebbe senso se la funzione non fosse
implementata anche in win95.
Quindi, o nell'help delle API hanno scritto una cavolata megagalattica,
oppure nel Q140570
hanno fatto casino, e forse nella frase:
"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. "
intendevano dire semplicemente che in Windows95 non si puo' usare MoveFileEx
per muovere un file attualmente in uso.
Se si gira la frase del Q140570 cosi':
""Windows 95 does not implement MoveFileEx() to move, replace, or delete
files (but not directories) that are currently in use, but does provide an
alternate way for all Win32-based, 16-bit Windows-based, and MS-DOS-based
applications.", mi pare che quadri un po' di piu', anche se il verbo
"implement" e' un tantino fuorviante.
Chiaramente questa e' solo una mia ipotesi, per confermarla (se qualcuno ne
avesse voglia), basta fare un piccolo test e vedere se MoveFileEx e'
implementata o no.
Io ho Win98 e non ho tempo (ne', sinceramente, voglia) di fare la verifica.
Se qualcuno prova, fate sapere sul NG, thanks.
--
Roal Zanazzi
z...@iol.it